akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;
const int MOD = 9999973;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
//二項係数の計算をしたい時用

const int MAX = 5100000;

unsigned long long fac[MAX], finv[MAX], inv[MAX];
unsigned ll kaijyo(ll n){
    if(n == 0) return 1;
    return n * kaijyo(n - 1);
}

unsigned ll ansans(ll n, ll k){
    return kaijyo(n) / kaijyo(n - k) / kaijyo(k);
}
ll fact[MAX], fact_inv[MAX];

// 繰り返し二乗法
ll power(ll a, ll b){
    ll res=1;
    while(b>0){
        if(b&1) res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])*fact_inv[n-r];
}

//テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    COMinit();
    int n;
    cin >> n;
    map<string, int> dict;
    rep(i, n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        dict[s] ++;

    }
    unsigned ll ans = 0;
    
    for( auto i = dict.begin(); i != dict.end() ; ++i ) {
        int ggg = i->second;
        //cout << i->first << " " << ggg << endl;
        //cout << ggg << endl;
        if(ggg >= 2){
            if(ggg % 2 == 0){
                unsigned ll ffff = ggg / 2;
                ans += ffff * (ggg - 1);
            }else{
                unsigned ll ffff = (ggg - 1) / 2;
                ans += ffff * (ggg);
            }
            //ans += ggg * (ggg - 1) / 2;
        }
    }
    cout << ans << endl;



}

Measured memory_bytes: 132608
k, n = map(int, input().split())
arr = sorted(list(map(int, input().split())))

maxDistance = 0

for i in range(n-1):
  maxDistance = max(maxDistance, arr[i+1]-arr[i])

maxDistance = max(maxDistance, arr[0]+(k-arr[-1]))

print(k-maxDistance)

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

int main(){
    int n;
    cin >> n;
    vector<int> hai(n);
    for(int i = 0; i< n; i++){
        cin >> hai[i];
    }

    int o = 100000000;
    for(int i = 1; i <= 100;i++){
        int s = 0;
        for(int j = 0; j < n; j++){
            s = s + (hai[j] - i) * (hai[j] - i);
        }
        o = min(o , s);
    }
    cout << o << endl;
    
    
}

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

int main(){
    double pai=3.141592653589;
    int a,b,C;
    double S,L,h,rad,cs;
    scanf("%d %d %d",&a,&b,&C);
    rad=C*pai/180;
    cs=sqrt(a*a+b*b-2*a*b*cos(rad));
    h=b*sin(rad);
    printf("%.8lf\n%.8lf\n%.8lf\n",h*a/2,a+b+cs,h);
    return 0;
}


Measured memory_bytes: 3408
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    rep(i, 1<<3) {
        int num = s[0] - '0';
        string ans = "";
        ans += s[0];
        rep(j, 3) {
            if ( (i>>j) & 1 ) {
                num += ( s[j+1] - '0' );
                ans += "+";
                ans += s[j+1]; 
            } 
            else {
                num -= ( s[j+1] - '0' );
                ans += "-";
                ans += s[j+1];
            }
        }
        ans += "=7";
//        cout << ans << endl;
        if ( num == 7 ) {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
 
const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;
 
int main() {
  int n, d;
  cin >> n >> d;
  vector<vl> x(n, vl(d, 0));

  rep(i, n) {
    rep(j, d) {
      cin >> x[i][j];
    }
  }

  int num = 0;
  rep(i, n) {
    for(int j = i + 1; j < n; j++) {
      int sum = 0;
      rep(k, d) {
        int diff = x[i][k] - x[j][k];
        if (diff < 0) {
          diff *= -1;
        }
        sum += diff * diff;
      }
      double root = round(sqrt(double(sum)));
      double squared = root * root;
      double err = squared - double(sum);
      if (err < 1e-4 && err > -1e-4) {
        num += 1;
      }
    }
  }

  cout << num << endl;

  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
s=input()[::-1]
ans=[]
now=0
while(now<n):
  t=1
  for i in reversed(range(1,m+1)):
    if now+i>n or s[now+i]=='1':
        continue
    now=now+i
    ans.append(i)
    t=0
    break
  if t:
    print(-1)
    exit()
ans.reverse()
print(*ans,sep=' ')

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};


int main() {
  int h,w; cin >> h >> w;
  vector<vector<char>> data(60, vector<char>(60,'A'));
  for(int i=1; i<=h; i++){for(int j=1; j<=w; j++){
    cin>>data[i][j];
  }}
  for(int i=1; i<=h; i++){for(int j=1; j<=w; j++){
    if(data[i][j]=='.'){
      char cur='0';
      rep(k,8){ if(data[i+dy[k]][j+dx[k]]=='#'){cur++;} }
      data[i][j]=cur;
    }
    cout<<data[i][j];
  }cout<<endl;}
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(n), cntr(10001);
	for (int i = 0; i < n; i++) {
		cin >> v.at(i);
		cntr.at(v.at(i))++;
	}

	for (int i = 1; i < 10001; i++) {
		cntr.at(i) += cntr.at(i - 1);
	}

	vector<int> ans(n);
	for (int i = v.size() - 1; i >= 0; i--) {
		ans.at(cntr.at(v.at(i)) - 1) = v.at(i);
		cntr.at(v.at(i))--;
	}

	for (int i = 0; i < n; i++) {
		if (i) cout << ' ';
		cout << ans.at(i);
	}
	cout << endl;
}


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

#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);
const int T = 1e5+5;
int ans[T];
vector<int> g[T];

bool bfs(int need) {
    queue<int> fila;
    fila.push(1);
    ans[1] = 1;

    while(!fila.empty()) {
        int u = fila.front();
        fila.pop();
        need--;
        for(int v : g[u]) {
            if(!ans[v]) {
                ans[v] = u;
                fila.push(v);
            }
        }
    }
    return (!need);
}

int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;

    while(m--) {
        int u,v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }

    if(bfs(n)) {
        cout << "Yes\n";
        for(int i = 2; i <= n; i++) cout << ans[i] << endl;
    } else cout << "No\n";

    return 0;
}



Measured memory_bytes: 10496
using System;
using System.Collections.Generic;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {


            var tmp = Console.ReadLine();
            var N = tmp[tmp.Length - 1].ToString();

            string result = "";

            if (N == "2" || N == "4" || N == "5" || N == "7" || N == "9")
            {
                result = "hon";

            } else if (N == "0" || N == "1" || N == "6" || N == "8")
            {
                result = "pon";

            } else if (N == "3")
            {
                result = "bon";
            }


            Console.WriteLine(result);



#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


Measured memory_bytes: 17464
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
string S,T;
  cin>>S>>T;
  int count=0;
  for(int i=0;i<3;i++){
  if(S.at(i)==T.at(i)){
  count++;}
  }
cout<<count<<endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    string ans = "";
    while(n!=0){
        int r = n % 2;
        if(r<0)r += 2;
        n = (n-r) / -2;
        ans += (char)('0' + r);
    }
    if(ans == "")ans = "0";
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			char[] t = scanner.next().toCharArray();
			// sを2つ結合する
			char[] newS = new char[2 * s.length];
			System.arraycopy(s, 0, newS, 0, s.length);
			System.arraycopy(s, 0, newS, s.length, s.length);
			boolean result = false;
			for (int i = 0; i < s.length; i++) {
				int count = 0;
				while ((count < s.length) && (newS[i + count] == t[count])) {
					count++;
				}
				if (s.length == count) {
					result = true;
					break;
				}
			}
			System.out.println(result ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35108
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(p):
    for edge in G[p]:
        if X[edge[0]] is not None:
            if X[edge[0]] - X[p] != edge[1]:
                print('No')
                exit()
        else:
            X[edge[0]] = X[p] + edge[1]
            dfs(edge[0])


N, M = map(int, input().split())
G = [[] for _ in range(N)]

for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    G[L].append((R, D))
    G[R].append((L, -D))

X = [None] * N
for i in range(N):
    if X[i] is None:
        X[i] = 0
        dfs(i)

print('Yes')


Measured memory_bytes: 128996
class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
def cal(d,xl):
    N=len(xl)
    for i in range(N-1):
        r1=abs(xl[i+1][0]-xl[i][0])
        try:
            l=d[r1]
            l.append([xl[i+1][1],xl[i][1]])
            d[r1]=l
        except:
            d[r1]=[[xl[i+1][1],xl[i][1]]]
    return d
N=int(input())
x=[[0,0] for _ in range(N)]
y=[[0,0] for _ in range(N)]
for i in range(N):
    x[i][0],y[i][0]=list(map(int,input().split()))
    x[i][1],y[i][1]=i,i
x=sorted(x,key=lambda l: l[0])
y=sorted(y,key=lambda l: l[0])
a=cal(cal({},x),y)
p=UnionFind(N)
c=0
cost=0
edgecount=0
while True:
    if(edgecount==N-1):
        print(cost)
        break
    try:
        l=a[c]
        for item in l:
            if(p.union(item[0],item[1])):
                cost+=c
                edgecount+=1
            
        c+=1
    except:
        c+=1
        continue

Measured memory_bytes: 62328
#include <iostream>//for cin cout endl
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL<<60;
const int MAX_N=110,MAX_V=100100;
int N;
long long W,weight[MAX_N],value[MAX_N];
long long dp[MAX_N][MAX_V];
int main(){
    cin>>N>>W;
    for (int i=0;i<N;++i)cin>>weight[i]>>value[i];
    for (int i=0;i<MAX_N;++i)for(int j=0;j<MAX_V;++j)dp[i][j]=INF;
    dp[0][0]=0;
    
    for (int i=0;i<N;++i){
        for (int sum_v=0;sum_v<MAX_V;++sum_v){
            if(sum_v-value[i]>=0)chmin(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i]);
            chmin(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }
    long long res=0;
    for (int sum_v=0;sum_v<MAX_V;++sum_v){
        if(dp[N][sum_v]<=W)res=sum_v;
    }
    cout<<res<<endl;

}

Measured memory_bytes: 86272
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <limits>
#include <utility>

namespace n91 {

u64 rsub(const u64 l, const u64 r) { return l < r ? r - l : 0; }

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  const usize k = n - scan<usize>() + 1;

  std::vector<u64> h(n);
  for (auto &e : h) {
    std::cin >> e;
  }
  h.insert(h.begin(), 0);
  h.insert(h.end(), 0);
  auto dp = md_vec(k + 1, n + 2, std::numeric_limits<u64>::max() / 2);
  dp[0][0] = 0;
  for (const usize i : rep(1, k + 1)) {
    for (const usize j : rep(1, n + 2)) {
      for (const usize k : rep(0, j)) {
        chmin(dp[i][j], dp[i - 1][k] + rsub(h[j], h[k]));
      }
    }
  }
  std::cout << dp[k][n + 1] << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              "\n"

#define pi acos(-1.0)
#define mod 1000000007

///Library
#define mem(a,b) memset(a,b,sizeof(a))
#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sq(x) (x)*(x)


///vector
#define Lower_bound(vec,value) lower_bound(vec.begin(),vec.end(),value)
#define Upper_bound(vec,value) upper_bound(vec.begin(),vec.end(),value)


/*template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
*/
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,sum=0;
    string b;
    cin>>a>>b;
    for(int i=0; i<a; i++)
    {
        if(b[i]=='A' && b[i+1]=='B' && b[i+2]=='C')
        {
            sum++;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

ll n;
ll ans;

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

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;

class program
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var str = Console.ReadLine().Split(' ');
        var A = new int[N];

        for (var i = 0; i < N; i++)
        {
            A[i] = int.Parse(str[i]);
        }

        for (var i = 0; i < N; i++)
        {
            var v = A[i];
            var j = i - 1;
            while (j >= 0 && A[j] > v)
            {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            show(A);
        }
    }

    public static void show(int[] A)
    {
        for (int i = 0; i < A.Length; i++)
        {
            if (i == 0)
            {
                Console.Write(A[i]);
            }
            else
            {
                Console.Write(" {0}", A[i]);
            }
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 5852
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
  int n;
  cin >> n;
  vector<int> nums;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    nums.push_back(temp);
  }
  int min_cost = INF;
  int answer;
  sort(nums.begin(), nums.end());
  // for (int i = 0; i < n; i++) cout << nums[i] << " ";
  // cout << endl;
  for (int i = nums[0]; i <= nums[n - 1]; i++) {
    // cout << i << " ";
    int current = i;
    int current_cost = 0;
    // cout << "Current : " << current_cost << endl;
    for (int j = 0; j < n; j++) {
      current_cost += (current - nums[j]) * (current - nums[j]);
    }
    if (current_cost < min_cost) {
      min_cost = current_cost;
      answer = i;
    }
    // cout << "Current : " << current_cost << endl;
  }
  // cout << min_cost << " " << answer << endl;
  cout << min_cost << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
#define lowbit(x) (x & (-x))
#define ls (rt << 1)
#define rs (rt << 1 | 1)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1000000 + 10;
char s[maxn];
int a[maxn], f[maxn][2];
int n;
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; ++i) a[i] = s[i] - '0'; 
	f[n][0] = a[n];
	f[n][1] = 10 - a[n];
	for(int i = n - 1; i; --i)
	{
		f[i][0] = f[i + 1][0] + a[i];
		if(a[i] + 1 <= 9) f[i][0] = min(f[i][0], f[i + 1][1] + a[i] + 1);
		f[i][1] = f[i + 1][1] + (10 - a[i] - 1) % 10;
		if(a[i] > 0)
		f[i][1] = min(f[i][1], f[i + 1][0] + (10 - a[i]) % 10);
	}
	printf("%d\n", min(f[1][0], f[1][1] + 1));
	return 0;
}

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

int main()
{
  int n, m, l;
  cin >> n >> m >> l;
  ll a[n][m] = {}, b[m][l] = {}, c[n][l] = {};

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

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

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < l; ++j)
    {
      if (j == 0)
        cout << c[i][j];
      else
        cout << ' ' << c[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3240
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll INF = -1;

int solve(void);

int main(void)
{
	while (solve())
	{
	}

	return 0;
}

int solve(void)
{

	ll N;
	cin >> N;

	vector<ll> h(N, 0);
	for (int i = 0; i < N; i++)
		cin >> h[i];

	// dp[i] := 足場 i にたどり着くまでに支払うコストの総和の最小値
	vector<ll> dp(N, INF);
	dp[0] = 0;

	for (int i = 0; i < N; i++)
	{
		for (int k = 1; k < 3; k++)
		{
			const ll ik = i + k;
			if (!(ik < N)) { continue; }

			const auto next = dp[i] + abs(h[ik] - h[i]);
			dp[ik] = dp[ik] == INF ? next : min(dp[ik], next);
		}
	}

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

Measured memory_bytes: 1792
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    if sum(a[j]*b[j] for j in range(m)) + c > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
mod=10**9+7
k=int(input())
s=input()
l=len(s)
fact=[1]
for i in range(1,k+l+1):
  fact.append((fact[-1]*i)%mod)
revfact=[]
for i in range(k+l+1):
  revfact.append(pow(fact[i],mod-2,mod))
pows1=[1]
pows2=[1]
for i in range(1,k+l+1):
  pows1.append((pows1[-1]*25)%mod)
  pows2.append((pows2[-1]*26)%mod)
ans=0
for i in range(l,l+k):
  ans+=pows2[l+k-i-1]*fact[i]*revfact[i-l]*revfact[l]*pows1[i-l]
  ans%=mod
ans+=fact[l+k]*revfact[k]*revfact[l]*pows1[k]
ans%=mod
print(ans)

Measured memory_bytes: 241556
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int h, w, k;
int M[30][30];

int CM[30][30];
int cnt[30][30];

int score(int y, int x) {
    rep(cy, h) rep(cx, w) { CM[cy][cx] = M[cy][cx]; }
    CM[y][x] = -1;
    int disappear = 0;
    int phase = 0;
    int c = -1;
    int ans = 0;
    while (disappear > 0 || phase <= 1) {
        phase++;
        disappear = 0;
        rep(cy, h) rep(cx, w) {
            if (cx == 0)
                cnt[cy][cx] = 1;
            else
                cnt[cy][cx] = (CM[cy][cx] != -1 && (CM[cy][cx] == CM[cy][cx - 1])) ? (cnt[cy][cx - 1] + 1) : 1;
        }
        rep(cy, h) {
            int r = 0;
            rrep(cx, w) {
                if (CM[cy][cx] != -1) {
                    if (r > 0) {
                        disappear += CM[cy][cx];
                        CM[cy][cx] = -1;
                        r--;
                    } else if (cnt[cy][cx] >= k) {
                        r = cnt[cy][cx] - 1;
                        disappear += CM[cy][cx];
                        CM[cy][cx] = -1;
                    }
                }
            }
        }
        rep(cx, w) {
            int pos = h - 1;
            rrep(cy, h) {
                if (CM[cy][cx] != -1) {
                    CM[pos--][cx] = CM[cy][cx];
                    if (pos + 1 != cy) {
                        CM[cy][cx] = -1;
                    }
                }
                if (pos < 0) break;
            }
        }
        ans += pow(2, c++) * disappear;
    }
    return ans;
}

int main() {
    cin >> h >> w >> k;
    char c;
    rep(y, h) rep(x, w) cin >> c, M[y][x] = c - '0';
    int ans = 0;
    rep(y, h) rep(x, w) ans = max(ans, score(y, x));

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

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

public class Main {

	public static void main(String[] args) {
		OriginScanner os = new OriginScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = os.nextInt();
		String s = os.next();
		
		char a = 'A';
		StringBuilder sb = new StringBuilder(); 
		for (int i = 0; i <= ('Z' - 'A'); i++) {
			sb.append(a++);
		}
		String str = sb.toString();
		sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			int it = str.indexOf(s.charAt(i)) + n;
			it = it > (str.length() - 1) ? it - str.length() : it;
			sb.append(str.charAt(it));
		}
		pw.println(sb.toString());
		pw.close();
	}
	
	static class OriginScanner {
		private BufferedReader br;
		private StringTokenizer st;
		
		public OriginScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String nextLine() {
			String str = null;
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
		String next() {
			if (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    bool right_triangle = false;
    if (a * a + b * b == c * c) right_triangle = true;
    else if (b * b + c * c == a * a) right_triangle = true;
    else if (a * a + c * c == b * b) right_triangle = true;
    if (right_triangle)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 1152
# include <iostream>

using namespace std;

//https://atcoder.jp/contests/abc086/tasks/abc086_a

int main(){
    int a,b;

    cin >> a >> b;

    if(a * b % 2 == 1 ){
    cout << "Odd" << endl;
    } 
    else if(a * b %2 == 0 ){
    cout << "Even" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in [None] * n]
b = [int(input()) for _ in [None] * m]
for i in a:
    c = 0
    for j, k in zip(i, b):
        c += j * k
    print(c)


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

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            string[] ps = Console.ReadLine().Split(' ');
            int[] intps = ps.Select((x, i) => { return int.Parse(x); }).ToArray();
            int count = 0;
            for(int i = 1;i < int.Parse(n) - 1; i++)
            {
                int[] r = new int[] { intps[i - 1], intps[i], intps[i + 1] };
                if(r.Max() != intps[i] && r.Min() != intps[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int cnt[26];
  REP(i,26)cnt[i]=0;
  string S;
  cin >> S;
  REP(j,S.size()){
      if (cnt[S[j]-'a']==0){
          cnt[S[j]-'a'] = 1;
      }else{
          cout << "no" << endl;
          return 0;
      }
  }
  cout << "yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll now = 0;
  mp[now]++;
  rep(i, n){
    ll num;
    cin >> num;
    now += num;
    mp[now]++;
  }
  ll sum = 0;
  for(p : mp){
    sum += (p.second * (p.second-1))/2;
  }
  cout << sum << endl; 
  return 0;
}
      
      

Measured memory_bytes: 12800
from collections import defaultdict
N = int(input())
a = [int(x) for x in input().split()]
d = defaultdict(int)

for k in range(N):
    d[a[k]] += 1

S = 0

for key in d:
    num = d[key]
    S += num * (num - 1) // 2

for k in range(N):
    num = d[a[k]]
    if num:
        print(S - num + 1)
    else:
        print(S)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define sec second
#define pii pair<int, int>
int n, m, k, x, y, sum, ans, a[100005];
bool ok[100005];
int main () {
	scanf("%d %d", &n, &m);
	for (int i=1; i<=n; i++) a[i]=1;
	ok[1]=true;
	for (int i=0; i<m; i++) {
		scanf("%d %d", &x, &y);
		if (ok[x]) {
			if (a[x]==1) {
				a[x]--;
				a[y]++;
				ok[x]=false;
				ok[y]=true;
			} else {
				a[x]--;
				a[y]++;
				ok[y]=true;
			}
		} else {
			a[x]--;
			a[y]++;
		}
	}
	for (int i=1; i<=n; i++) ans+=(ok[i]==true);
	printf("%d\n", ans);
	return 0;
}

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

const int MAXN = 100 + 5;

int N, Ans;
int A[MAXN << 1];

inline int read()
{
	register int x = 0;
	register char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch))
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x;
}

int main()
{
	N = read() << 1;
	for(int i = 1; i <= N; ++i) A[i] = read();
	std::sort(A + 1, A + 1 + N);
	for(int i = 1; i <= N; i += 2) Ans += A[i];
	printf("%d\n", Ans);
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func prefix(s string, k int) string {
	if len(s) <= k {
		return s
	}
	res := s[:k]
	if len(s) > k {
		res += "..."
	}
	return res
}

func main() {
	var K int
	var s string
	fmt.Scan(&K, &s)
	fmt.Println(prefix(s, K))
}


Measured memory_bytes: 1768
#include<iostream>

using namespace std;
 
int main(){
  int x[10],tmp,i,j;

  for(i=0; i<10; ++i)
    cin >> x[i];

  for(i=0; i<10; ++i){
    for(j=i+1; j<10; ++j){
      if(x[i] < x[j]){
	tmp = x[i];
	x[i] = x[j];
	x[j] = tmp;
      }
    }
  }

  for(i=0; i<3; ++i)
    cout << x[i] << "\n";

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int t[n+1],x[n+1],y[n+1];

    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    for(int i = 0;i<n;i++){
        int T = t[i+1] - t[i];
        int D = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if( T < D || T%2 != D%2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M, S = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append((v, a, b))
    edge[v].append((u, a, b))
CD = tuple(tuple(map(int, input().split())) for _ in range(N))

inf = 10**18
U = N*50
S = min(S, U)
dist = [[inf] * (U + 1) for _ in range(N)]
dist[0][S] = 0

que = [(0, -S, 0)]  # 時間、現在地、銀貨の数
while que:
    time, silver, now = heapq.heappop(que)
    silver = -silver
    if dist[now][silver] < time:
        continue
    # 両替する
    c, d = CD[now]
    n = 1
    while silver + c * n <= U:
        if dist[now][silver + c * n] > time + n * d:
            dist[now][silver + c * n] = time + n * d
            heapq.heappush(que, (time + n * d, -(silver + c * n), now))
            n += 1
        else:
            break
    # 移動する
    for nxt, s, t in edge[now]:
        if silver < s:
            continue
        if dist[nxt][silver - s] > time + t:
            dist[nxt][silver - s] = time + t
            heapq.heappush(que, (time + t, -(silver - s), nxt))

for i in range(1, N):
    print(min(dist[i]))

Measured memory_bytes: 55000
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string now = "0000000";
string num[10] = {"0111111", "0000110", "1011011", "1001111", "1100110"
                 ,"1101101", "1111101", "0100111", "1111111", "1101111"};
string res;
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(n == -1)break;

    res.resize(7);
    now = "0000000";
    rep(i, n){
      int(x);
      rep(j, 7){
        if(now[j] != num[x][j])res[j] = '1';
        else res[j] = '0';
        now[j] = num[x][j];
      }
      pri(res);
    }


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3192
import java.util.*;

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

        Integer N = sc.nextInt();
        Map<String, Integer> judgeCount = new HashMap<>();

        for (int i = 0; i < N; i++){
            String key = sc.next();
            if (judgeCount.containsKey(key)) {
                judgeCount.replace(key, judgeCount.get(key)+1);
            } else {
                judgeCount.put(key, 1);
            }
        }

        System.out.println("AC x " + judgeCount.getOrDefault("AC", 0));
        System.out.println("WA x " + judgeCount.getOrDefault("WA", 0));
        System.out.println("TLE x " + judgeCount.getOrDefault("TLE", 0));
        System.out.println("RE x " + judgeCount.getOrDefault("RE", 0));
    }
}

Measured memory_bytes: 58768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    int x,y;cin>>x>>y;
    int ansx=0,ansy=0;
    int a[]={0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    
        if(a[x]==a[y])cout << "Yes" <<endl;
        else cout << "No" << endl;
    
    return 0;
}





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

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;
	int dis = b-a;
	if (dis % 2 == 0) {
		cout << "Alice" << endl;
	} else {
		cout << "Borys" << endl;
	}
	return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll n , m ; 
  cin >> n >> m ;
  
  intll ans = 0 ; 
  ans = (n-2) * (m-2) ;
  if(n*m == max(n,m)  ) ans = max(n,m) - 2 ;
  if(n == 1 && m == 1 ) ans = 1 ;
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
bool check(int m, char c, int l, int r){
    bool res = true;
    if(m == 0){
        if(c == 'o'){
            if(l != r) res = false;
        }else{
            if(l == r) res = false;
        }
    }else{
        if(c == 'o'){
            if(l == r) res = false;
        }else{
            if(l != r) res = false;
        }
    }
    return res;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    string v[4] = {"00", "01", "10", "11"};
    rep(i,4){
        vector<int> t(n);
        rep(j,2) t[j] = (v[i][j] == '0') ? 0 : 1;

        FOR(k, 1, n-1){
            if(t[k] == 0){
                if(s[k] == 'o'){
                    t[k+1] = t[k-1];
                }else{
                    t[k+1] = 1-t[k-1];
                }
            }else{
                if(s[k] == 'o'){
                    t[k+1] = 1-t[k-1];
                }else{
                    t[k+1] = t[k-1];
                }
            }
        }

        if(!check(t[n-1], s[n-1], t[n-2], t[0])) continue;
        if(!check(t[0], s[0], t[n-1], t[1])) continue;

        rep(l, n) printf("%c", t[l] == 0 ? 'S' : 'W');
        cout << endl;
        return 0;
    }

    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 1016
N = int(input())
s = [sorted(input()) for i in range(N)]

ans = 0
aDict = {}
for i in s:
  if str(i) not in aDict:
    aDict[str(i)] = 1
  else:
  	aDict[str(i)] += 1
    
for n in aDict.values():
    ans += (n*(n-1)//2)
print(ans)


        

      



Measured memory_bytes: 130648
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int n; cin >> n;
    string s; cin >> s;
    int x = 0;
    vi X(n);
    rep(i, 0, n) {
        if (s[i] == 'I') {
            ++x;
            X.push_back(x);
        }
        else {
            --x;
            X.push_back(x);
        }
    }
    cout << *max_element(all(X)) << endl;
    return 0;
}

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

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,count;
  scanf("%d",&N);
  //int num[N];
  //for(int i=0;i<N;i++) scanf("%d",&num[i]);
  printf("%d",24-N+24);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};

template<typename T> class TreeDPRerooting
{
    using Func=function<T(T,T)>;
    vector<vector<edge>> G;
    int N;
    Func merge,lift;
    T e; // identity element

public:
    vector<vector<T>> sumL,sumR;
    vector<T> dp,res;
    
    TreeDPRerooting(vector<vector<edge>> G,Func merge,Func lift,T e):
        G(G),merge(merge),lift(lift),e(e),N(G.size()),dp(N),sumL(N),sumR(N),res(N)
    {
        dfs(0,-1);
        reroot(0,-1);
    } 
    T dfs(int v,int par)
    {
        // TreeDP
        T res=e;
        for(edge e:G[v]) if(e.to!=par){
            res=merge(res,lift(dfs(e.to,v),e.cost));
        }
        return dp[v]=res;
    }
    void reroot(int v,int par)
    {
        // accumulate children's information from left and right
        sumL[v].assign(G[v].size()+1,e);
        sumR[v].assign(G[v].size()+1,e);
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            sumL[v][i+1]=merge(sumL[v][i],lift(dp[e.to],e.cost));
        }
        for(int i=G[v].size()-1;i>=0;i--){
            edge e=G[v][i];
            sumR[v][i]=merge(sumR[v][i+1],lift(dp[e.to],e.cost));
        }
        // calculate res[v] using children's information(L[v],R[v],dp)
        res[v]=sumR[v][0];
        // reroot v with its children
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(e.to!=par){
                int tmp=dp[v];
                dp[v]=merge(sumL[v][i],sumR[v][i+1]);
                reroot(e.to,v);
                dp[v]=tmp;
            }
        }
    }
};

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

    int N,M; cin>>N>>M;
    vector<vector<edge>> G(N);
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back({b,1});
        G[b].push_back({a,1});
    }
    auto merge=[&](int a,int b)
    {
        return a*b%M;
    };
    auto lift=[&](int a,int cost)
    {
        return (a+1)%M;
    };
    TreeDPRerooting<int> treedp(G,merge,lift,1LL);
    for(int i:treedp.res) cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 45312
#include <iostream>
 
using namespace std;
typedef unsigned long long int ull;
 
int main()
{
    ull const by[] = { 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625, 1220703125 };
 
    ull n;
    while( cin >> n, n ) {
        ull t = 0;
        for( auto const& i : by ) {
            t += n / i;
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 1148
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{   int a,y=0,n,i,t,h[1001];
   float th[1001],x=114514191;
    scanf("%d%d%d",&n,&t,&a);
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
        th[i]=t-h[i]*0.006-a;
    }
    for(i=0;i<n;i++){
        if(fabs(th[i])<x){
            x=fabs(th[i]);
            y=i;
        }
    }
    y++;
    printf("%d",y);

    return 0;
}


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

//ios::sync_with_stdio(false);

using namespace std;

const int INF = (1<<30) - 1;

int bfs(vector<string>& field, pair<int, int> start, pair<int, int> end){
    int dh[] = {0, 0, 1, -1};
    int dw[] = {1, -1, 0, 0};
    
    int H = field.size();
    int W = field[0].size();
    vector<vector<int> > d(H, vector<int>(W, INF));
    queue<pair<int, int> > nodes;
    
    d[start.first][start.second] = 0;
    nodes.push(start);
    
    while(!nodes.empty()){
        auto node = nodes.front(); nodes.pop();
        for(int i=0; i<4; i++){
            int nh = dh[i] + node.first;
            int nw = dw[i] + node.second;
            
            if(0<=nh&&nh<H && 0<=nw&&nw<W && field[nh][nw] != 'X' && d[nh][nw] == INF){
                d[nh][nw] = d[node.first][node.second] + 1;
                
                if(nh == end.first && nw == end.second)
                    return d[nh][nw];
                
                nodes.push(make_pair(nh, nw));
            }
        }
    }
    return -1;
}

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    
    vector<string> field(H);
    for(int i=0; i<H; i++)
        cin >> field[i];
    
    vector<pair<int, int> > cheeses(N+1);
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            char& c = field[i][j];
            if(c == 'S'){
                cheeses[0] = make_pair(i, j);
            }else if(c != '.' && c != 'X'){
                cheeses[c-'0'] = make_pair(i, j);
            }
        }
    }
    
    
    int ans = 0;
    for(int i=0; i<N; i++){
        ans += bfs(field, cheeses[i], cheeses[i+1]);
    }
    
    cout << ans << endl;
    
	return 0;
}

Measured memory_bytes: 6060