akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int q; cin >> q;
    bool rev = 0;
    int op,f;
    char x;
    string a[2];

    while(q--) {
        cin >> op;
        if(op == 1) rev = !rev;
        else {
            cin >> f >> x;
            if(f == 1) {
                if(rev) a[1].pb(x);
                else a[0].pb(x);
            } else {
                if(rev) a[0].pb(x);
                else a[1].pb(x);
            }
        }
    }
    reverse(a[0].begin(), a[0].end());
    s = a[0] + s + a[1];
    if(rev) reverse(s.begin(),s.end());
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 1288
#20C10のcombinatrics全探索？
#本番でCでこれ見たら凍るw
#少なくとも combinatrics が組込みでなかったら C問題 じゃないな
n,m,q=map(int, input().split( ))
qs=tuple(tuple(map(int, input().split( ))) for _ in range(q))
import itertools
ans=0
for comb in itertools.combinations(range(1,n+m),n):##+1ない?
    tmp=0
    comb2=[comb[i]-i for i in range(n)]
    for ai,bi,ci,di in qs:
        if comb2[bi-1]-comb2[ai-1]==ci:
            tmp+=di 
    ans=max(ans,tmp)
print(ans)


Measured memory_bytes: 68424
import numpy as np

MAX = 10**6
is_prime = [True] * MAX
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(2*i, MAX, i):
            is_prime[j] = False

a = np.cumsum([i+1 for i in range(100)])

def decomp(n):
    res = {}
    for p in primes:
        while n % p == 0:
            if not p in res:
                res[p] = 0
            res[p] += 1
            n //= p
    if n > 1:
        res[n] = 1
    return res

def solve(n):
    ans = 0
    for num in decomp(n).values():
        k = 0
        while a[k] <= num:
            k += 1
        ans += k
    return ans

n = int(input())
print(solve(n))

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

int main() {
    int n, l=0, r=0;
    cin >> n;

    string s, ans;
    cin >> s;

    for (int i=0; i<n; i++) {
        if (s.at(i) == '(') r++;
        else {
            if (r > 0) r--;
        }

        if (s.at(n-1-i) == ')') l++;
        else {
            if (l > 0) l--;
        }
    }

    ans = string(l, '(') + s + string(r, ')');

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int d_max = 105;
const int k_max = 100005; 

signed main(){
    string s;
    int d;
    cin >> s >> d;
    int n = s.size();

    int dp[k_max][d_max][2];
    REP(i,n+1) REP(j,d) REP(k,2) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    REP(i,n){
        REP(j,d){
            REP(k,10){
                if(k < s[i] - '0') dp[i+1][(j + k) % d][1] += dp[i][j][0],dp[i+1][(j + k) % d][1]%= MOD;
                else if( k == s[i] - '0') dp[i+1][(j+k)%d][0] += dp[i][j][0],dp[i+1][(j+k)%d][0] %= MOD;
                else break;
            }
            REP(k,10) dp[i+1][(j+k) %d][1] += dp[i][j][1], dp[i+1][(j+k) %d][1]%= MOD;

        }
    }

    cout << (dp[n][0][0] + dp[n][0][1] + MOD - 1) % MOD << endl;

}

Measured memory_bytes: 18560
package main

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

func isPrime(x int) bool {
	if x <= 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}
	for d := 3; d*d <= x; d += 2 {
		if x%d == 0 {
			return false
		}
	}
	return true
}

func main() {
	n := 0
	fmt.Scan(&n)
	ans := 0
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		s.Scan()
		x, _ := strconv.Atoi(s.Text())
		if isPrime(x) {
			ans++
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 1264
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,a,b,t,i,j;
vector<int> s1,s0,ans,nxt;
int main(){
	cin>>n>>a>>b;
	t=a^b;
	if(t==0){
		puts("NO");
		return 0;
	}
	for(i=0;i<n;i++){
		if((t>>i)&1){
			s1.push_back(i);
		}
		else{
			s0.push_back(i); 
		}
	}
	if(s1.size()%2==0){
		puts("NO");
		return 0;
	}
	ans.push_back(0);
	ans.push_back(1<<s1[0]);
	for(i=1;i<s1.size();i+=2){
		nxt.clear();
		int x=(1<<s1[i]),y=(1<<s1[i+1]);
		for(j=0;j<ans.size();j+=2){
			if(j==0){
				nxt.push_back(ans[j]);
				nxt.push_back(ans[j]+x);
				nxt.push_back(ans[j]+x+y);
				nxt.push_back(ans[j]+y);
			}
			else{
				nxt.push_back(ans[j]+x+y);
				nxt.push_back(ans[j]+x);
				nxt.push_back(ans[j]);
				nxt.push_back(ans[j]+y);
			}
			nxt.push_back(ans[j+1]+y);
			nxt.push_back(ans[j+1]);
			nxt.push_back(ans[j+1]+x);
			nxt.push_back(ans[j+1]+x+y);
		}
		ans=nxt;
	}
	for(i=0;i<s0.size();i++){
		nxt.clear();
		int x=(1<<s0[i]);
		for(j=0;j<ans.size();j+=2){
			nxt.push_back(ans[j]);
			nxt.push_back(ans[j]+x);
			nxt.push_back(ans[j+1]+x);
			nxt.push_back(ans[j+1]);
		}
		ans=nxt;
	}
	puts("YES");
	for(i=0;i<ans.size();i++){
		printf("%d%c",a^ans[i],(i+1==ans.size()?'\n':' '));
	}
	return 0;
}

Measured memory_bytes: 4640
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();
		int X=sc.nextInt();
		int count=0;
		for(int a=0;a<=A;a++){
			for(int b=0;b<=B;b++){
				for(int c=0;c<=C;c++){
					if((a*500+b*100+c*50) == X){
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> as;
  F0R(i, S.size() - 1) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      as.push_back(i);
    }
  }
  F0R(i, Q) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << (lower_bound(rng(as), r) - lower_bound(rng(as), l)) << newl;
  }
}
#endif


Measured memory_bytes: 3976
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    int n;
    cin >> n;
    string s;
    int a;
    pair<pair<string,int>,int>list[n];
    rep(i, n)
    {
        cin >> s >> a;
        list[i] = mp(mp(s,-a), i);
    }
    sort(list, list+n);
    rep(i, n) cout << list[i].second + 1<<endl;
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int mo = 1e9 + 7;
int a[2][2], b[2][2];
int n, m, K, all, cnt1, cnt2;
char str[1111][1111];
inline void mul(int a[2][2], int b[2][2], int c[2][2]) {
  static int ans[2][2]; memset(ans, 0, sizeof ans);
  for (int i = 0; i < 2; i ++)
    for (int k = 0; k < 2; k ++)
      for (int j = 0; j < 2; j ++)
        ans[i][j] = (ans[i][j] + a[i][k] * b[k][j]) % mo;
  c[0][0] = ans[0][0];
  c[0][1] = ans[0][1];
  c[1][0] = ans[1][0];
  c[1][1] = ans[1][1];         
}

main(void) {
  read(n); read(m); read(K);
  for (int i = 1; i <= n; i ++) {
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= m; j ++)
      all += str[i][j] == '#';
  }
  int up = 0, ver = 0;
  for (int i = 1; i <= n; i ++)
    ver += str[i][1] == '#' && str[i][m] == '#';
  for (int i = 1; i <= m; i ++)
    up += str[1][i] == '#' && str[n][i] == '#';
  for (int j = 1; j <= m; j ++) {
    for (int i = 1; i <= n - 1; i ++)
      cnt1 += str[i][j] == '#' && str[i + 1][j] == '#';
  }
  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= m - 1; j ++)
      cnt2 += str[i][j] == '#' && str[i][j + 1] == '#';
  }
  if (ver && up)
    cout << "1\n";
  else if (!ver && !up) {
    int ans = 1, a = all % mo;
    for (-- K; K; K >>= 1, a = a * a % mo)
      if (K & 1) ans = ans * a % mo;
    cout << ans << "\n";
  } else {
    if (ver) swap(ver, up), swap(cnt1, cnt2);
    // cout << up << " " << cnt1 << " " << all << "\n";
    a[0][0] = up; a[0][1] = cnt1; a[1][1] = all;
    b[0][0] = 1; b[1][1] = 1;
    -- K;
    for (; K; K >>= 1, mul(a, a, a))
      if (K & 1) mul(a, b, b);
    int ans = (b[1][1] - b[0][1] + mo) % mo;
    cout << ans << "\n";
  }
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(void){
   int m,f,b;
   cin>>m>>f>>b;
   if (m>b){
       cout<<0<<endl;
  }else if(m+f<b){
       cout<<"NA"<<endl;
   }else if (m<b){
       cout<<b-m<<endl;
  
  
   }
   }


Measured memory_bytes: 3116
def resolve():
    N = int(input())
    ans = 0
    counts = [1 for _ in range(N+1)]
    for i in range(2, N+1):
        j = 1
        while i*j <= N:
            counts[i*j] += 1
            j += 1

    for i in range(1, N+1):
        ans += i*counts[i]
    print(ans)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 224392
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var P = parseInt(input[0].split(" ")[1]);
  var ans = Math.floor((A*3+P)/2);

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
DSU = atcoder.dsu.DSU

#!/usr/bin/env python3

# from atcoder.dsu import DSU
import math
N, M = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
AB = [list(map(int, input().split())) for _ in range(M)]

g = DSU(N)

for a, b in AB:
    g.merge(a-1, b-1)

grp = g.groups()

if grp == None:
    print(0)
else:
    print(len(grp) - 1)

Measured memory_bytes: 42312
#include <iostream>
#include <cstdio>

using namespace std;

int width, depth;
int s_w, s_d;
bool is_visit[20 + 2][20 + 2];
char field[20 + 2][20 + 2];
int t_x[4] = {1, 0, -1, 0};
int t_y[4] = {0, -1, 0, 1};


int search(int w, int d)
{
  //  printf("(%d, %d)\n", w, d);
  if (is_visit[d][w]) return 0;
  if (field[d][w] == '#') return 0;
  is_visit[d][w] = true;
  int sum = 0;
  for (int i = 0; i < 4; i++) {
    sum += search(w + t_x[i], d + t_y[i]);
  }
  return sum + 1;
}

int main()
{
  while (scanf("%d %d ", &width, &depth) == 2) {
    if (width == 0 && depth == 0) {
      break;
    }
    for (int i = 0; i < 22; i++) {
      fill(is_visit[i], &is_visit[i][22], false);
      fill(field[i], &field[i][22], '#');
    }
    for (int i = 1; i <= depth; i++) {
      for (int j = 1; j <= width; j++) {
	scanf("%c ", &field[i][j]);
	if (field[i][j] == '@') {
	  s_w = j, s_d = i;
	}
	//	printf("%c", field[i][j]);
      }
      //      printf("\n");
    }
    
    printf("%d\n", search(s_w, s_d));
  }
}

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

int main(){
  int a, b, s, x=0;

  while(cin >> a >> b){
    s=a+b;
    while (s>0){
      x++;
      s/=10;
    }
    cout << x << endl;
		 x=0;
		 
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int a[212345];
bool b[1123456];
signed main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	int n, i, ans = 0, j, q;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (i = 1; i < n; ++i) {
		if (a[i] == a[i - 1]) {
			b[a[i]] = 1;
		}
	}
	for (i = 0; i < n; ++i) {
		if (b[a[i]])continue;
		q = int(sqrt(a[i])) + 1;
		for (j = 1; j < q; ++j) {
			if (a[i] % j == 0 && (b[j]||b[a[i]/j])) {
				--ans;
				break;
			}
		}
		++ans;
		b[a[i]] = 1;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end()

const int INF=INT_MAX;
const ld PI=3.1415926535897932384626433;
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}
int gcd(int a,int b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}

ld log (ld a,ld b){return log(b)/log(a);}
void solve();

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    //  cin >> t;
    //  while(t--)
    solve();
    return 0;
}

void solve(){
    int n;
    cin >> n;
    unordered_map<string , int> m;
    while(n--){
        string s;
        cin >> s;
        m[s]++;
    }
    int mx=0;
    for(auto x:m)
        mx=max(mx,x.second);
    vector<string> ans;
    for(auto x:m)
        if(x.second==mx)
            ans.push_back(x.first);
    sort(all(ans));
    for(string s:ans)
        cout << s << "\n";
}





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

int main()
{
  int n, x;
  cin >> n >> x;
  int m[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    sum += m[i];
  }
  sort(m, m + n);
  if (x < sum) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (x >= m[i]) {
        ans++;
        x -= m[i];
      }
      else {
        cout << ans << endl;
        return 0;
      }
    }
  }
  else {
    cout << n + ((x - sum) / m[0]) << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int H,W;
int x,y,flg;
string str;
int t[200][200];
void compute(){
  int a;
  if(t[y][x]==-1)return;
  if(t[y][x]==-2)flg=1;
  else {
    a=t[y][x];
    t[y][x]=-2;
    y=y+dy[a];
    x=x+dx[a];
    compute();
  }
}
int main(){
  while(cin>>H>>W){
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++){
      cin>>str;
      for(int j=0;j<W;j++){
    if(str[j]=='^')t[i][j]=0;
    else if(str[j]=='>')t[i][j]=1;
    else if(str[j]=='v')t[i][j]=2;
    else if(str[j]=='<')t[i][j]=3;
    else t[i][j]=-1;
      }
    }
    x=y=flg=0;
    compute();
    if(flg)cout<<"LOOP"<<endl;
    else cout<<x<<' '<<y<<endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int i,a[5];
	for(i=0;i<6;i++){
		scanf("%d",&a[i]);
	}

	int j,l,flag = 0;
	for(j=0;j<5;j++){
		for(l=0;l<4;l++){
			if(a[5]<abs(a[j]-a[l])){
			flag = 1;
			}
		}
	}

	if(flag == 0){
		printf("Yay!");
	}else if(flag == 1){
		printf(":(");
	}

	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#define N 100000
#define MAX (1<<31)-1
using namespace std;
int A[N], T[4*N], lazy[4*N];

void build(int l, int r, int k) {
    if (l == r) {
        T[k] = A[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, k * 2);
    build(mid + 1, r, k * 2 + 1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
void pushdown(int k) {
    if (lazy[k] != -1) {
        lazy[2*k] = lazy[k];
        lazy[2*k+1] = lazy[k];
        T[2*k] =  lazy[k];
        T[2*k+1] = lazy[k];
        lazy[k] = -1;
    }
}
void updata(int L, int R, int data ,int l, int r ,int k) {
    if (L <= l && r <= R) {
        T[k] = data;
        lazy[k] = data;
        return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    if (mid >= L) updata(L, R, data, l, mid, 2*k);
    if (mid < R) updata(L, R, data, mid+1, r, 2*k+1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
int find(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) return T[k];
    pushdown(k);
    int mid = (l + r) / 2;
    int ans = MAX;
    if (mid >= L) ans = min(ans, find(L, R, l, mid, k * 2));
    if (mid < R) ans = min(ans, find(L, R, mid + 1, r, k * 2 + 1));
    return ans;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++)
        A[i] = MAX;
    for (int i = 0; i < 4*n; i++)
        lazy[i] = -1;
    build(0, n - 1, 1);
    int com, s, t, x, y;
    while (q--) {
        scanf("%d", &com);
        if (com == 0) {
            scanf("%d%d%d", &s, &t, &x);
            updata(s, t, x, 0, n - 1, 1);
        }
        else {
            scanf("%d%d", &s, &t);
            printf("%d\n", find(s, t, 0, n - 1, 1));
        }
    }
    return 0;
}


Measured memory_bytes: 5728
#include <iostream>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
  int N, A[100];
  cin >> N;
  rep(i,N) cin >> A[i];
  string str = "APPROVED";
  rep(i,N){
    if(A[i]%2 == 0){
      if((A[i]%3)*(A[i]%5) != 0){
        str = "DENIED";
        break;
      }
    }
  }
  cout << str << endl;
}

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

int main(){
    int64_t n, k; cin >> n >> k;
    int64_t h[n];
    rep(i, n) cin >> h[i];

    int64_t dp[n];
    memset(dp, 1, sizeof(dp));
    dp[0] = 0;
    loop(i, 1, n){
        loop(j, 1, k+1){
            if(i - j >= 0) dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std;
long long a,b,c,m,n;
int main()
{
	cin>>a>>b>>c;
	m=4*a*b,n=(c-a-b)*(c-a-b);
	if(c<=a+b)
		cout<<"No"<<endl;
	else if(m<n)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
N ,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
inf = max(A[0]**2,A[-1]**2)
ok1 = inf
ng1 = -inf
while (abs(ok1 - ng1) > 1):
    arg = (ok1 + ng1) // 2
    ans = 0
    for i in range(N):
        if A[i] * A[i] < arg :
            ans -= 1
        ok = N
        ng = -1
        if A[i] == 0:
            if arg > 0:
                ans += N
        elif A[i] > 0:
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ng = mid
                else:
                    ok = mid
            ans += ok
        else: 
            while (abs(ok - ng) > 1):
                mid = (ok + ng) // 2
                if A[i] * A[mid] < arg:
                    ok = mid
                else:
                    ng = mid       
            ans += N-ok   
    ans /= 2
    if K>ans:
        ng1 = arg
    else:
        ok1 = arg
print(ng1)


Measured memory_bytes: 94604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 500000

struct Node{
  int key;
  struct Node *r, *l, *p;
};
void insert(int);
void inOrder(struct Node *);
void preOrder(struct Node *);
struct Node *root, *NIL;
int main() {
  int i,m,z;
  char command[10];
  scanf("%d",&m);
  for (i = 0; i < m ; i++) {
    scanf("%s",command);
    if (strcmp(command,"insert")==0) {
      scanf("%d",&z);
      insert(z);
    }
    else if (strcmp(command,"print")==0) {
      inOrder(root);
      printf("\n");
      preOrder(root);
      printf("\n");
    }
  }
  return 0;
}
void insert(int n) {
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = n;
  z->l = NIL;
  z->r = NIL;

  while ( x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->l;
    }
    else{
      x = x->r;
    }
  }
  z->p = y;
  if (y == NIL) {
    root = z;
  }else{
    if (z->key < y->key) {
      y->l = z;
    }else{
      y->r = z;
    }
  }
}
void inOrder(struct Node *v){
  if (v == NIL) {
    return;
  }
  inOrder(v->l);
  printf(" %d",v->key);
  inOrder(v->r);
}
void preOrder(struct Node *v){
  if (v == NIL) {
    return;
  }
  printf(" %d",v->key);
  preOrder(v->l);
  preOrder(v->r);
}



Measured memory_bytes: 25128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  double n,k;cin>>n>>k;
  double ans = 0;
  repd(i,1,n+1){
    if(i >= k){
      ans += 1/n;continue;
    }
    ans += 1/(pow(2,ceil(log2(k/i)))*n);
  }
  cout << setprecision(12) <<  ans << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> A;
    for (int i = 0; i < N; ++i){
        int a;
        cin >> a;
        A.push_back(make_pair(a, i));
    }

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

    for (int i = 0; i < N; ++i){
        cout << A[i].second + 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[11],ar[11];
    cin>>s;
    int j=0;
    int l=strlen(s);
    for(int i=0;i<l;i++)
    {
        if((s[i]=='0')||(s[i]=='1'))
        {
            ar[j]=s[i];
            j++;
        }
        else if((s[i]=='B'))
        {
            j--;
            if(j<0)
            {
                j=0;
            }
        }

    }
        for(int i=0;i<j;i++)
        cout<<ar[i];
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())
mx = a if x >= y else b
if c * 2 <= (a+b):
  if c * 2 <= mx:
    print((min(x,y)+abs(x-y))*c*2)
  else:
    print(min(x,y)*c*2+abs(x-y)*mx)
else:
  print(a*x+b*y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){


    int n;
    cin>>n;

    vi data(n);

    rep(i,n){
        int x,y;
        cin>>x>>y;
        if (x==y){
            data.at(i)=1;
        }
        else {
            data.at(i)=0;
        }

    }


    string answer="No";

    for (int i=0;i<=n-3;i++){
        if (data.at(i)==1 and data.at(i+1)==1 and data.at(i+2)==1){
            answer="Yes";
        }
    }

    cout<<answer<<endl;












}

Measured memory_bytes: 3596
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<cmath>
#include<limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;

 
int main() {
    int k, a,b; cin >> k >> a >> b;
    bool flag = false;
    for (int i = a; i <= b; i++){
        if (i%k == 0){
            flag = true;
        }
    }

    if (flag){
        cout << "OK";
    }
    else{
        cout << "NG";
    }
    
    



    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0337
{
    class Program
    {
        static int[] staEra = new int[] { 1868, 1912, 1926, 1989 };
        static string[] chrEra = new string[] { "M", "T", "S", "H" };

        static void Main(string[] args)
        {
            int[] ey = RArInt();
            if (ey[0] == 0)
            {
                for (int i = staEra.Length - 1; i >= 0; i--)
                {
                    if (ey[1] >= staEra[i])
                    {
                        Console.WriteLine(chrEra[i] + (ey[1] - staEra[i] + 1).ToString());
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine(staEra[ey[0] - 1] + ey[1] - 1);
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 17940
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, m = map(int, input().split())

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

###具体例###
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    unite(a - 1, b - 1)

ans = -float('inf')

for i in range(n):
    ans = max(ans, size(i))

print(ans)

Measured memory_bytes: 73144
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = n - 1;
	for(ll i = 1; i*i <= n; ++i){
		if(n%i != 0) continue;
		ll j = n / i;
		chmin(ans, i + j - 2);
	}
	cout << ans << endl;
	return 0;
}


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

namespace AtCoder.Abc
{
    class A_WeLoveGolf_165
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long k = long.Parse(Console.ReadLine());
            
            // 整数配列の入力
            var inputlongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long a = inputlongArray[0];
            long b = inputlongArray[1];

            string result = "";

            for (long i = a;i <= b;i++)
            {
                if (i % k == 0)
                {
                    result = "OK";
                    break;
                }
                else if (i == b)
                {
                    result = "NG";
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

int main()
{
  int N;
  int p[21];
  int res=0;
  cin >> N;

  rep(i,N) cin >> p[i];

  for(int i=1; i<N-1; i++){
    if(p[i-1] < p[i] && p[i] < p[i+1]) res++;
    else if(p[i-1] > p[i] && p[i] > p[i+1]) res++;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        list<int> li;
        list<int>::iterator it;
            char str[20];
            int inp;
        while(n--){
            scanf("%s", str);
            if(str[0] == 'i'){
                scanf("%d", &inp);
                li.push_front(inp);
            }else if(str[6] == 'F'){
                li.pop_front();
            }else if(str[6] == 'L'){
                li.pop_back();
            }else if(str[0] == 'd'){
                scanf("%d", &inp);
                for(it = li.begin(); it != li.end(); it++){
                    if(*it == inp){
                         li.erase(it);
                         break;
                    }
                }
            }
        }
        for(it = li.begin(); it != li.end(); it++){
            if(it == li.begin()) cout << *it;
            else cout << ' ' << *it;
        }
        cout << endl;
    }
}

Measured memory_bytes: 32420
#include "bits/stdc++.h"
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int n;
  int h, w;
  cin >> n >> h >> w;

  for(int i =0;i < n;++i){
    int a, b;
    cin >> a >> b;
    if (h <= a && w <= b) ++num;
  }
  
  cout << num << endl;
  return 0;
}


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

using namespace std;

int main() {
	long long D, N;
	cin >> D >> N;
	if (N % 100 == 0) N++;
	int t = 1;
	while (D--) {
		t *= 100;
	}
	cout << N * t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  double cnt;
  cin >> cnt;
  cout << fixed << setprecision(6);
  cout << 2*cnt*3.1415926 << endl;
}

Measured memory_bytes: 3772
# 回答を見て作成：一致検索はsort＋一致で時間がかかる？
n = int(input())
a = [int(x.strip()) for x in input().split()]
b = []
ans = str('')
for i in enumerate(a):
  b.append(i)
b.sort(key=lambda x:x[1])
for i in b:
  print(i[0]+1)

Measured memory_bytes: 24784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    
    ll ans = 1;
    rep(i, n) {
        ans *= (ll)(i+1);
        ans %= mod;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int N;
int K;
int x;

signed main()
{
    cin >> N;
    cin >> K;
    int ans = 0;
    REP(i,N) {
        cin >> x;
        ans += min(x, K - x) * 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
ip = input().split()
usdata = []
D = int(ip[0])
N = int(ip[1])
flag = 0

b_number = 100 ** D
a_number = b_number * N
tester = a_number % 100 ** (D + 1)

if tester == 0:
    a_number += 100 ** D

print(a_number)

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  int N;cin>>N;
  vector<int> as(N);
  REP(i,N) cin>>as[i];
  int mean = accumulate(ALL(as),0)/N;
  int tmp1 = 0;
  int tmp2 = 0;
  REP(i,N) {
    tmp1 += pow(as[i]-mean,2);
    tmp2 += pow(as[i]-mean-1,2);
  }
  OUT(min(tmp1,tmp2));

  return 0;
}

Measured memory_bytes: 256
N,K=map(int, input().split())
A=list(map(int, input().split()))
D,E=[],[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append(0)
  elif i>0:
    D.append(i)
    scnt+=1
  else:
    E.append(i)
    fcnt+=1
mod=10**9+7
ans=1
#全て使う場合は問答無用でかける
if K==N:
  for i in A:
    ans*=i
    ans%=mod
  print(ans)
  exit()
#マイナスを奇数個絶対かける→確実に答えはマイナス
if K%2==1 and max(A)<0:
  A=sorted(A)[::-1]
  for i in range(K):
    ans*=A[i]
    ans%=mod
  print(ans)
  exit()
#絶対0をかけなきゃいけない
if K>scnt+fcnt:
  print(0)
  exit()
D,E=sorted(D)[::-1],sorted(E)
#print(D,E)
ans=1
cnt=0
a,b=0,0
while K-cnt>1:
  if a+1<=len(D)-1 and b+1<=len(E)-1:
    d,e=D[a]*D[a+1],E[b]*E[b+1]
    if d>e:
      ans*=D[a]
      a+=1
      cnt+=1
      ans%=mod
    else:
      ans*=e
      b+=2    
      ans%=mod
      cnt+=2
  elif a+1<=len(D)-1:
    d=D[a]*D[a+1]
    ans*=D[a]
    a+=1
    cnt+=1
    ans%=mod
  elif b+1<=len(E)-1:
    e=E[b]*E[b+1]
    ans*=e
    b+=2
    cnt+=2
    ans%=mod

if K-cnt==1:
  Z=[]
  if a!=scnt:
    Z.append(D[a])
  if b!=fcnt:
    Z.append(E[-1])
  if 0 in A:
    Z.append(0)
  ans*=max(Z)
  ans%=mod
print(ans)

Measured memory_bytes: 110548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef tuple<int, int, int> rec;

int main()
{
	cin.sync_with_stdio(false);
	int h, w;
	vector<rec> v;
	FOR(i, 1, 151)FOR(j, 1, i)
	{
		v.emplace_back(i*i+j*j, j, i);
	}
	sort(ALL(v));
	while (cin >> h >> w, h)
	{
		REP(i, v.size())
		{
			rec tmp = make_tuple(h*h + w*w, h, w);
			if (v[i] == tmp)
			{
				cout << get<1>(v[i + 1]) << " " << get<2>(v[i + 1]) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
char s[100];int le,i;
bool flg=false;;;;int
main()        {scanf(
"%s",s        );;i++;
i--;le        =strlen
(s);;;        for(i=0
;i<le;i++){if(flg){if
(s[i]=='F'){;cout<<""
<<"Yes"<<endl;;return
0;};;}        else{if
(1&&s[        i]=='C'
){flg=        true;}}
};cout        <<"No";
cout<<        endl;;;
return        0;i++;}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	ll x;
	cin >> x;
	for(ll a = 1;a <= 3981;a++){
		ll b = a * a * a * a * a - x;
		for(ll j = -3981;j <= 3981;j++){
			if(j * j * j * j * j == b){
				cout << a << " " << j << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	string s; cin >> s;

	int count_ng = 0;
	for (char c : s) {
		if (c == 'x') count_ng++;
	}

	if (count_ng < 8) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

set<ll>sset;
ll mas=3234566667;
map<string,int>used;


void dfs(string t){
	int k=t.size();
	int last=t[k-1]-'0';
	deque<string>cand;
	rep(i,3){
		string now=t;
		int d=-1+i;
		if(last+d>=0&&last+d<10){
			now.push_back('0'+last+d);
		}
		ll num=stoll(now);
		if(mas>=num&&!used[now]){
			sset.insert(num);
			used[now]++;
			dfs(now);

		}
	}
	
}

void solve()
{
	int n;
	cin>>n;	
	rep(i,9){
		string m="0";
		m[0]+=i+1;
		//cout<<m<<endl;
		sset.insert(i+1);
		dfs(m);
	}
	auto i=sset.begin();
	int cnt=0;
	ll ans;
	while(i!=sset.end()){
		//cout<<*i<<endl;
		if(cnt==n-1){
			ans=*i;
			break;
		}
		i++;
		cnt++;
	}
	cout<<ans<<endl;

}

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


Measured memory_bytes: 17280
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
ans = 0
for i in dic:
    if dic[i] < i:
        ans += dic[i]
    else:
        ans += dic[i]-i
print(ans)


Measured memory_bytes: 17780
num = int(input())
taro = 0
hanako = 0
for _ in range(num):
    a, b = map(str, input().split())
    if a > b:
        taro += 3
    elif a < b:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print(taro, hanako)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, D, Ans = 0;cin >> N >> D;
vector<ll> X(N);
vector<ll> Y(N);

rep(i, 0, N)cin >> X[i] >> Y[i];

rep(i, 0, N){

    double dis = sqrtl(X[i]*X[i] + Y[i]*Y[i]);

    if(D >= dis)Ans++;

}
cout << Ans;
}

Measured memory_bytes: 6432