akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

class BinaryIndexedTree
{
public:
  ll N;
  vector<ll> bit;

  BinaryIndexedTree(ll n)
  {
    N = n;
    bit = vector<ll>(N + 1, 0); // 1 ~ N なので注意
  }

  ll sum(ll i)
  {
    ll s = 0;
    while (i > 0)
    {
      s += bit.at(i);
      i -= i & -i;
    }
    return s;
  }

  void add(ll i, ll x)
  {
    while (i <= N)
    {
      bit.at(i) += x;
      i += i & -i;
    }
  }
};

int main()
{
  using BIT = BinaryIndexedTree;

  ll N;
  cin >> N;
  string S;
  cin >> S;

  vector<BIT> B(26, BIT(N));
  for (ll i = 1; i <= N; i++)
  {
    B.at(S.at(i - 1) - 'a').add(i, 1);
  }

  ll Q;
  cin >> Q;
  for (ll q = 0; q < Q; q++)
  {
    ll qt;
    cin >> qt;
    if (qt == 1)
    {
      ll i;
      char c;
      cin >> i >> c;
      B.at(S.at(i - 1) - 'a').add(i, -1);
      S.at(i - 1) = c;
      B.at(c - 'a').add(i, 1);
    }
    else
    {
      ll l, r;
      cin >> l >> r;

      ll ans = 0;
      for (ll j = 0; j < 26; j++)
      {
        ans += (B.at(j).sum(r) - B.at(j).sum(l - 1) >= 1);
      }

      cout << ans << endl;
    }
  }
}

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

void solve(){
    int n;
    cin>>n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int num;
        cin>>num;
        if(num%2==1 && i%2==1)ans++;
    }
    cout<<ans<<endl;
    return;
}

signed main()  
{  
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}  


Measured memory_bytes: 3632
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		try{
			String s;
			int sum=0;
			int l=0;
			while((s=reader.readLine()) !=null){
				int d=Integer.parseInt(s);
				for(int i=0;i<(600/d);i++){
					sum +=d*l*l;
					l +=d;
				}
				System.out.println(sum);
				sum=0;
				l=0;
			}
		}catch(IOException e){
			System.exit(0);
		}
	}
}

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

int main(){
    int i,j,a,b;
    for(int n=0;n<3;n++){
        cin >> i;
        if(n == 0){
            a = i;
        }
        else if(a > i){
            a = i;
        }
    }
    for(int n=0;n<2;n++){
        cin >> j;
        if(n == 0){
            b = j;
        }
        else if(b > j){
            b = j;
        }
    }
    cout << a+b-50 << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;

    int c = 0;

    for(int i = 0;i < 2 ;i++){
        if(a <= b){
            c = c + b;
            b = b - 1;
        }    
        else{
                 c = c + a;
                 a = a - 1;

            }
           
    }
    
    cout << c << endl;

}

Measured memory_bytes: 384
{-# LANGUAGE RankNTypes #-}

{-
This answer was written after referring to the editorial.
-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.List
import Control.Monad
import Debug.Trace

bigP = 998244353

addM x y = (x + y) `mod` bigP
multM x y = (x * y) `mod` bigP
subtM x y = (bigP + x - y) `mod` bigP
negM x = subtM 0 x

vec_pow = VU.fromListN 2010 $ iterate (multM 2) 1
pow2M = (VU.!) vec_pow

vec_fact = VU.fromListN 4020 $ scanl' multM 1 [1..]
fact = (VU.!) vec_fact

{-
  "memovec mf size" is a function created from mf using vector 
  memoization.
  mf defines the calculation of the vector.  For example, if you
  want the fibonacci function: 

      mf :: Monad m => (Int -> m Int) -> (Int -> m Int)
      mf act 0 = return 1
      mf act 1 = return 1
      mf act n = (+) <$> act (n-1) <*> act (n-2)

      fib :: Int -> Int
      fib = memovec mf 100000
-}
memovec :: VU.Unbox a =>
           (forall m. Monad m => (Int -> m a) -> (Int -> m a)) ->
           Int -> (Int -> a)
memovec mf size = (VU.!) vecx
  where vecx = VU.create $ do
          v <- VUM.new size
          forM_ [0..size-1] $ \i -> mf (VUM.read v) i >>= VUM.write v i
          return v

mfinv act 0 = return 0 -- dummy
mfinv act 1 = return 1
mfinv act n = do
  let (a,b) = divMod bigP n
  x <- act b
  return ((negM a) `multM` x)

inv = memovec mfinv 4030

vec_inv_fact = VU.fromListN 4024 $ scanl' f 1 [1..]
  where f s t = s `multM` (inv t)
inv_fact = (VU.!) vec_inv_fact

-- cmb m r | trace ("cmb " ++ show (m,r)) False = undefined
cmb m r = (fact m) `multM` (inv_fact r) `multM` (inv_fact (m-r))

solve :: Int -> Int -> [Int]
solve k n =
  map s_solve [2..2*k]
  -- map s_solve [2]
  where

  s_solve t = 
    -- trace ("s_solve " ++ show [t,a,xx]) xx
    xx
    where a = num_diff_pair t
          xx = foldl' addM 0 [face_cnt_cstr_tot t p (a-p) | p <- [0..a]]
  
  face_cnt m r 
    | mm >= 0 && rr >= 0 && mm >= rr = cmb mm rr
    | otherwise                      = 0
    where mm = m+r-1
          rr = r-1

  -- z: (1+)
  -- y: 0
  -- w: 1
     -- face_cnt_cstr z y w
     -- | trace ("face_cnt_cstr " ++ show (n,k,z,y,w)) False = undefined
  face_cnt_cstr z y w = face_cnt (n-z-w) (k-y-w)

  -- p: 1+/0
  -- q: 0/0
  -- u: 1 if k/2 should be 1
  -- v: 1 if k/2 should be 0
  face_cnt_cstr_tot t p q = xx
    where xx = (cmb (p+q) p) `multM` (pow2M p) `multM` e
          e | t `mod` 2 == 1 = face_cnt_cstr p (p+2*q)   0
            | otherwise =      face_cnt_cstr p (p+2*q)   1
                             + face_cnt_cstr p (p+2*q+1) 0

{-
k == 7
2 -> 0
3 -> 1  (1-2/2-1)
4 -> 1  (1-3/3-1)
5 -> 2  (1-4/4-1, 2-3/3-2)
6 -> 2  (1-5/5-1, 2-4/4-2)
7 -> 3  (1-6/6-1, 2-5/5-2, 3-4/4-3)
13 -> 1 (6-7/7-6)
12 -> 1 (5-7/7-5)
11 -> 2 (4-7/7-4, 5-6/6-5)
10 -> 2 (3-7/7-3, 4-6/6-4)
9  -> 3 (2-7/7-2, 3-6/6-3, 4-5/5-4)
8  -> 3 (1-7/7-1, 2-6/6-2, 3-5/5-3)
-}

  num_diff_pair t
    | t <= k    = (t-1) `div` 2
    | otherwise = (2*k - t + 1) `div` 2


main = do
  cont <- getContents
  let [k,n] = map read $ words cont
  putStr $ unlines $ map show $ solve k n


Measured memory_bytes: 1404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// Scanner sc = new Scanner(System.in);
		// 整数の入力
		// int a = sc.nextInt();
		// スペース区切りの整数の入力
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// 文字列の入力
		// String s = sc.next();
		// 出力
		// System.out11.println((a+b+c) + " " + s);

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		for (int i = 0; i < k; i++) {

			int[] result = getMax(a, b, c);
			a = result[0];
			b = result[1];
			c = result[2];

		}


		System.out.println(a + b + c);


	}

	private static int[] getMax(int a, int b, int c) {
		int[] newInput = new int[]{a, b, c};

		if (a <= b && c <= b) {
			newInput[1] = 2*b;
		} else if (b <= a && c <= a) {
			newInput[0] = 2*a;
		} else if (a <= c && b <= c) {
			newInput[2] = 2*c;
		}

		return newInput;

	}

}

Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
string name[50];
int t[50];
string ne;

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

	cin >> n;
	rep(i,n) {
		cin >> name[i] >> t[i];
	}

	cin >> ne;

	int ans = 0;
	rep(i, n) {
		ans += t[i];
		if (name[i] == ne)ans = 0;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define write_to_file() freopen("output.txt" , "w" , stdout)
#define read_from_file() freopen("input.txt" , "r" , stdin)
#define GeoOutputFix(VV) cout<<fixed<<setprecision(VV)
#define MAX_V  1e9
#define MIN_V -1e9
template<class T>istream& operator>> (istream& is, complex<T>& p){T value;is >> value, p.real(value), is >> value, p.imag(value);return is;}
typedef long long lld;
typedef pair<lld, lld> dd;
typedef complex<double> point;
#define X real()
#define Y imag()
#define dist(a , b) sqrt(pow(a.X - b.X , 2) + pow(a.Y- b.Y , 2))
#define dist2(a , b) ((long double)hypot(a , b))
#define mid(a,b) (((a)+(b))/point(2,0))
#define compare(a , b) (fabs(a.X - b.X) < -1e9 && fabs(a.Y - b.Y) < -1e9)
#define all(c) c.begin() , c.end()
#define MOD (lld)(1e9+7)
#define EPS 1e-9
#define neighbours(u , e , v) for(int e = head[u] , v ; v = to[e] , ~e ; e = nxt[e])
#define watch1(x) cout<<(#x)<<" = "<<x<<"\n"
#define watch2(x , y) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<<"\n"
#define watch3(x , y , z) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<"  "<<(#z)<<" = "<<(z)<<"\n"
int dr[] = {1 , 1 , 1 , 0 , 0 , -1 , -1 , -1};
int dc[] = {-1 , 0 , 1 , -1 , 1 , -1 , 0 , 1};
int ddr[] = {1 , 0 , 0 , -1};
int ddc[] = {0 , -1 , 1 , 0};
inline int SD(){int i ;scanf("%d", &i);return i;}
inline lld SLL(){lld i;scanf("%lld", &i);return i;}
inline char SC(){char i;scanf(" %c", &i);return i;}
const int AKA = 1e6 + 6 , OO = 0x3f3f3f3f;
//----------------------------------------[TO_OO]--[To infinity and beyond]--------------------------------------------------------
int a[AKA];
int main()
{
    string s[3];
    for(int i = 0 ; i < 3 ; ++i)
        cin>>s[i];
    for(int i = 0 , j = 0 ; i < 3 ; ++i , ++j)
        cout<<s[i][j];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807



void solve(void)
{
  int N , M;
  cin>>N>>M;

  vector<vector<int> > mat(N,vector<int>(M,0));
  vector<int> vec(M,0);

  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      cin>>mat[i][j];
    }
  }

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


  vector<int> out_vec(N,0);

  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      out_vec[i] += mat[i][j]*vec[j];
    }  
  }
  
  for (int i = 0; i < N; i++)
  {
    cout<<out_vec[i]<<endl;
  }
  
  
    
  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3168
L, N = map(int, input().split())
X = []
for i in range(N):
    X.append(int(input()))

X = sorted(X)

ma = 0
for k in range(2):
    if k == 1:
        X = [L-X[-i] for i in range(1, N+1)]
    s = X[0]
    for i in range(1, N):
        if i % 2 == 1:
            s += L - X[-(i//2)-1] + X[i//2]
        else:
            s += X[i//2] + (L - X[-(i//2)])

    ma = max(ma, s)
    lt = (N-1) // 2 if N % 2 == 1 else -N//2
    for i in range(1, N):
        if lt > 0:
            if N % 2 == 1:
                s += X[lt] - X[i-1]*2 - (L - X[lt + 1])
            else:
                s += X[lt] - X[i-1] * 2 - (L - X[lt + 1])
            lt = 1 + lt - N
            ma = max(ma, s)
        else:
            if N % 2 == 1:
                s += X[lt] - X[i-1] * 2 - (L - X[lt])
            else:
                s += X[lt]*2 - L - X[i-1] * 2
            lt = N + lt
            ma = max(ma, s)

print(ma)



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

struct dise{
 int lab1, lab2, lab3, lab4, lab5, lab6;
};

void s( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab5;
     d.lab5 = d.lab6;
     d.lab6 = d.lab2;
     d.lab2 = tmp;
}

void e( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab4;
     d.lab4 = d.lab6;
     d.lab6 = d.lab3;
     d.lab3 = tmp;
}

void n( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab2;
     d.lab2 = d.lab6;
     d.lab6 = d.lab5;
     d.lab5 = tmp;
}

void w( dise &d ){
     int tmp = d.lab1;
     d.lab1 = d.lab3;
     d.lab3 = d.lab6;
     d.lab6 = d.lab4;
     d.lab4 = tmp;
}

void lot( dise &d ){
     int tmp = d.lab2;
     d.lab2 = d.lab3;
     d.lab3 = d.lab5;
     d.lab5 = d.lab4;
     d.lab4 = tmp;
}

bool cheak( dise d1, dise d2 ){
 bool flag = false;

 for( int i=0; i<4; i++ ){
   for( int j=0; j<4; j++ ){
    if( d1.lab1==d2.lab1 && d1.lab2==d2.lab2 && d1.lab3==d2.lab3 && d1.lab4==d2.lab4 && d1.lab5==d2.lab5 && d1.lab6==d2.lab6 ){
      flag = true;
      break;
    }
    lot(d1);
   }
   if( flag ){
    break;
   }
   n(d1);
  }

  e(d1);

  for( int i=0; i<4; i++ ){
    for( int j=0; j<4; j++ ){
      if( d1.lab1==d2.lab1 && d1.lab2==d2.lab2 && d1.lab3==d2.lab3 && d1.lab4==d2.lab4 && d1.lab5==d2.lab5 && d1.lab6==d2.lab6 ){
        flag = true;
        break;
      }
      lot(d1);
    }
    if( flag ){
     break;
    }
    n(d1);
  }

 return flag;
}


int main(){
 dise a[100];
 int n;
 cin >> n;
 for( int i=0; i<n; i++ ){
  cin >> a[i].lab1 >> a[i].lab2 >> a[i].lab3 >> a[i].lab4 >> a[i].lab5 >> a[i].lab6;
 }

 bool result = false;
 for( int x=0; x<n-1; x++ ){
   for( int y=x+1; y<n; y++ ){
     result = cheak( a[x], a[y] );
     if( result ){
       break;
     }
   }
   if( result ){
     break;
   }
 }

 if( result ){
   cout << "No" << endl;
 }else{
   cout << "Yes" << endl;
 }

 return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll n;
  cin >> n;
  ll ct = 0, cx = 0, cy = 0;
  vector<ll> t(n), x(n), y(n);
  REP(i, n) { cin >> t[i] >> x[i] >> y[i]; }

  REP(i, n) {
    ll dt = t[i] - ct, dx = x[i] - cx, dy = y[i] - cy;
    ll d = abs(dx) + abs(dy);
    if (d > dt) {
      no();
    }
    if ((dt - d) % 2 == 1) {
      no();
    }
    cx = x[i];
    cy = y[i];
    ct = t[i];
  }
  yes();
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX_N = 1410;

int H, W, c[MAX_N][MAX_N], dp[MAX_N][MAX_N];

int getLargestSquare() {
	int maxWidth = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			dp[i][j] = (c[i][j] + 1) % 2;
			maxWidth |= dp[i][j];
		}
	}

	for (int i = 1; i < H; ++i) {
		for (int j = 1; j < W; ++j) {
			if (c[i][j]) dp[i][j] = 0;
			else {
				dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1]))+1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	}

	return maxWidth*maxWidth;
}


int main(int argc, char const *argv[])
{
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) scanf("%d", &c[i][j]);
	}

    printf("%d\n", getLargestSquare());
	return 0;
}


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

const int N = 410;
const int mod = 998244353;

typedef long long LL;

inline int Pow(int x, int y) {
    int res = 1;
    for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
    return res;
}    

int dp[2][N][N][N], A[N], B[N], C[N][N];

int main() {
    int n, s = 0; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", &A[i], &B[i]), s = (s + A[i]) % mod;
    for (int i = 0; i <= 400; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    }
    for (int i = 1, t = 0, t1 = 0; i <= n; t += B[i] - 1, t1 += A[i], i++) 
        for (int j = 0; j <= t; j++) 
            for (int k = 0; k <= t1; k++) {
                dp[0][i][j][k] = (dp[0][i][j][k] + dp[0][i - 1][j][k]) % mod;
                dp[1][i][j][k] = (dp[1][i][j][k] + dp[1][i - 1][j][k]) % mod;
                int p = (LL)k * Pow(k + A[i], mod - 2) % mod, p1 = Pow(p, j);
                for (int l = 0; l < B[i]; l++) {
                    int w = (LL)C[j + l][j] * p1 % mod * Pow(1 + mod - p, l) % mod;
                    dp[0][i][j + l][k + A[i]] = (dp[0][i][j + l][k + A[i]] + (LL)dp[1][i - 1][j][k] * w) % mod;
                    dp[1][i][j + l][k + A[i]] = (dp[1][i][j + l][k + A[i]] + (LL)dp[0][i - 1][j][k] * w) % mod;
                    if (k == 0 && j == 0) dp[1][i][l][A[i]] = (dp[1][i][j + l][A[i]] + w) % mod;
                }
            }
    int ans = 0;
    for (int t = 0; t <= 1; t++) 
        for (int j = 0; j <= 400; j++)
            for (int k = 0; k <= 400; k++) {
            	int w = (LL)dp[t][n][j][k] * s % mod * Pow(k, mod - 2) % mod;
            	if (t & 1) ans = (ans + w) % mod;
				else ans = (ans - w + mod) % mod; 
			}
    printf("%d\n", ans);
    return 0;    
}//

Measured memory_bytes: 527232
#include "bits/stdc++.h"
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define watch1(x) cout<<(#x)<<" = "<<(x)<<"\n"
#define watch2(x , y) cout<<(#x)<<" = "<<(x)<<"  "<<(#y)<<" = "<<(y)<<"\n"
#define watch3(x , y , z) cout<<(#x)<<" = "<<(x)<<"  "<<(#y)<<" = "<<(y)<<"  "<<(#z)<<" = "<<(z)<<"\n"
#define watch_size(x) cout<<"Size of "<<(#x)<<" = "<<x.size()<<"\n
#define write_to_file() freopen("output.txt" , "w" , stdout)
#define read_from_file() freopen("input.txt" , "r" , stdin)
#define GeoOutputFix(VV) cout<<fixed<<setprecision(VV)
#define MAX_V  1e9
#define MIN_V -1e9
template<class T>istream& operator>> (istream& is, complex<T>& p){T value;is >> value, p.real(value), is >> value, p.imag(value);return is;}
typedef long long lld;
typedef pair<lld, lld> dd;
typedef complex<double> point;
#define X real()
#define Y imag()
#define dist(a , b) sqrt(pow(a.X - b.X , 2) + pow(a.Y- b.Y , 2))
#define dist2(a , b) ((long double)hypot(a , b))
#define compare(a , b) (fabs(a.X - b.X) < -1e9 && fabs(a.Y - b.Y) < -1e9)
#define all(c) c.begin() , c.end()
#define MOD (lld)(1e9+7)
#define EPS 1e-9
#define neighbours(u , e , v) for(int e = head[u] , v ; v = to[e] , ~e ; e = nxt[e])
#define mod(x , y) (x % y + y) % y ;
int dr[] = {1 , 1 , 1 , 0 , 0 , -1 , -1 , -1};
int dc[] = {-1 , 0 , 1 , -1 , 1 , -1 , 0 , 1};
int ddr[] = {1 , 0 , 0 , -1};
int ddc[] = {0 , -1 , 1 , 0};
inline int SD(){int i ;scanf("%d", &i);return i;}
inline lld SLL(){lld i;scanf("%lld", &i);return i;}
inline char SC(){char i;scanf(" %c", &i);return i;}
const int AKA = 1e6 + 6 , N = 1e3+4;
map<string , int> m;
set<string> s;
int main()
{
    int n = SD();
    for(int i = 0 ; i < n ; ++i)
    {
        string ss;
        cin>>ss;
        sort(ss.begin() , ss.end());
        s.insert(ss);
        m[ss]++;
    }
    vector<int> cnt;
    lld ans = 0;
    for(auto x : s)
       if(m[x])
        cnt.push_back(m[x]);
    for(auto x : cnt)
        ans += (1LL * x * (x - 1)) / 2;
    printf("%lld\n" , ans);
}


Measured memory_bytes: 21244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
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 drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#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)
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 MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {

    string s;
    map<char,ll> m;
    cin>>s;
    for(int i=0;i<s.size();i++){
        m[s[i]]++;
    }
    ll sum=0;
    for(auto it=m.begin();it!=m.end();it++){
        sum+=(it->second)*((it->second)-1)/2;
    }
    ll n=(ll)s.size();
    cout<<n*(n-1)/2-sum+1<<endl;

}



Measured memory_bytes: 640
N = int(input())
A,B= map(int, input().split())
#a= int(input().split()
a_list = list(map(int, input().split())) # "1 2 3"と入力

test_a=0
test_b=0
test_c=0
for num in a_list:
    if num<= A:
        test_a += 1
    elif A< num<=B:
        test_b += 1
    else:
        test_c += 1
print(min(test_a,test_b,test_c))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ");
        int a1 = Integer.parseInt(line[0]);
        int a2 = Integer.parseInt(line[1]);
        int a3 = Integer.parseInt(line[2]);
        int a4 = Integer.parseInt(line[3]);
        int a5 = Integer.parseInt(line[4]);
        int a6 = Integer.parseInt(line[5]);
  
        int b = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < b; i++) {
            int c = scanner.nextInt();
            int d = scanner.nextInt();
            int result = 0;
            if (c == a1 || c == a6)
                if (d == a2)
                    result = 3;
                else if (d == a3)
                    result = 5;
                else if (d == a4)
                    result = 2;
                else
                    result = 4;
            else if (c == a2 || c == a5)
                if (d == a1)
                    result = 4;
                else if (d == a3)
                    result = 1;
                else if (d == a4)
                    result = 6;
                else
                    result = 3;
            else {
                if (d == a1)
                    result = 2;
                else if (d == a2)
                    result = 6;
                else if (d == a5)
                    result = 1;
                else
                    result = 5;
            }
            if (c == a4 || c == a5 || c == a6)
                result = 7 - result;
            System.out.println(line[result - 1]);
        }
    }
}



Measured memory_bytes: 26084
#include <bits/stdc++.h>
using ll = long long;
constexpr int MOD = 1000000007;
constexpr ll INF = 1000100010001000;
using namespace std;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> d(h, vector<char>(w));
  vector<vector<int>> ans(h, vector<int>(w, 0));
  vector<int> count(h, 0);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> d[i][j];
      if (d[i][j] == '#')
        count[i]++;
    }
  }
  int up = 0, down;
  bool sFlag = false;
  for (int i = 0; i < h; i++) {
    if (!sFlag && count[i] != 0) {
      up = i;
      sFlag = true;
    }
    if (count[i] != 0) {
      down = i;
    }
  }
  
  int id = 1;
  bool top = true;
  for (int i = 0; i < h; i++) {
    if(count[i] == 0)
      continue;
    bool first = true;
    for (int j = 0; j < w; j++) {
      if (d[i][j] == '#') {
        if (!first)
          id++;
        else
          first = false;
      }
      ans[i][j] = id;
    }
    id++;
  }
  
  for (int i = 0; i < h; i++) {
    if(count[i] != 0)
      continue;
    for (int j = 0; j < w; j++) {
      if (i <= up) {
        int n = 1;
        while(ans[i + n][j] == 0) {
          n++;
        }
        ans[i][j] = ans[i + n][j];
      }
      else {
        ans[i][j] = ans[i - 1][j];
      }
    }
  }
  
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j] << " ";
    }
    cout<< endl;
  }
  
  return 0;
}

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

#define MX 112345

int ar[MX];

int main() {
        int n, m;
        scanf("%d %d", &n, &m);
        while( m-- ) {
                int a, b;
                scanf("%d %d", &a, &b);
                ar[a] += 1, ar[b] += -1;
        }

        for(int i=2; i<n; i++) {
                ar[i] += ar[i-1];
        }
        bool flg = true;
        for(int i=1; i<n; i++) if( ar[i]&1 ) {
                flg = false;
                break;
        }

        if( flg ) printf("YES\n");
        else printf("NO\n");

        return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int k,n;

int main(){
    cin >> n >> k;
    int p[n]; for(int i=0; i<n; i++) cin >> p[i];
    sort(p,p+n);
    int ans = 0;
    for(int i=0; i<k; i++){
        ans += p[i];
    }
    cout << ans << endl;
}


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

int main()
{
    string s;
    int m;
    
    while (1) {
        cin >> s;
        if (s == "-")
            break;
        cin >> m;
        for (int i = 0; i < m; i++) {
            int h;
            cin >> h;
            s += s.substr(0, h);
            s.erase(0, h);
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3152
#include<iostream>
#include<queue>
#include<functional>
#include<algorithm>
#include<vector>
using namespace std;

typedef pair<long long, int>P;

#define MAX_N 150000
#define INF 100000000000000
priority_queue<P, vector<P>, greater<P>>Q;
vector<pair<int, long long>>X[MAX_N];
int N, M, A, B, C, O;
long long dist[MAX_N];
void dijkstra() {
	for (int i = 0; i < MAX_N; i++) {
		dist[i] = INF;
	}
	Q.push(make_pair(0, O)); dist[O] = 0;
	int cnt = 0;
	while (!Q.empty()) {
		cnt++;
		if (cnt >= 8000000 || Q.size() >= 2000000) { cout << "NEGATIVE CYCLE" << endl; return; }
		P pa = Q.top(); Q.pop();
		long long a1 = pa.first; int a2 = pa.second;
		for (int i = 0; i < X[a2].size(); i++) {
			int to = X[a2][i].first;
			if (dist[to] > a1 + X[a2][i].second) {
				dist[to] = a1 + X[a2][i].second;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (dist[i] == INF) { cout << "INF" << endl; }
		else { cout << dist[i] << endl; }
	}
	return;
}
int main() {
	cin >> N >> M >> O;
	for (int i = 0; i < M; i++) {
		cin >> A >> B >> C;
		X[A].push_back(make_pair(B, C));
	}
	dijkstra();
	return 0;
}

Measured memory_bytes: 40508
from collections import Counter

H, W, N = map(int, input().split())

# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]

# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        # 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            if (a + dy, b + dx) not in dict:
                dict[(a + dy, b + dx)] = 1
            else:
                dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]

# ans[1], ans[2], ..., ans[9]を確定させる（ans[0]は後述）
for k, v in c.items():
    if v > 0:
        ans[k] = v

# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for i in range(10):
    print(ans[i])


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

int main() {
    string S;
    cin >> S;
    
    int n = 0, m = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == '0') {
                n++;
            }
            else {
                m++;
            }
        }
        else {
            if (S[i] == '1') {
                n++;
            }
            else {
                m++;
            }
        }
    }
    
    cout << min(n, m) << endl;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
an = [0 for i in range(30)]
ans = []
for i in a:
    c = bin(i)
    d = len(c)-1
    count = 0
    while c[d] != 'b':
        if c[d] == '1':
            an[count] += 1
            an[count] %= 2
        d-=1
        count+=1
tmp = 0
for i in range(len(an)):
    if an[i] == 1:
        tmp += 2**i
for i in a:
    ans.append(i ^ tmp)
print(*ans)

Measured memory_bytes: 110684
#include<stdio.h>

#define SENTINEL 1000000000

int count = 0;

void Merge(int A[],int left,int mid,int right){
  int n1 = mid - left, n2 = right - mid;
  int i,j,k;
  int L[n1+1],R[n2+1];

  for(i = 0; i < n1; i++){
    L[i] = A[left+i];
  }
  for(i = 0; i < n2; i++){
    R[i] = A[mid+i];
  }

  L[n1] = SENTINEL;
  R[n2] = SENTINEL;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }else{
      A[k] = R[j];
      j = j + 1;
    }
  }
}

MergeSort(int A[], int left, int right){
  int mid;

  if(left+1 < right){
    mid = (left + right)/2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

int main(){
  int n,i;
  int A[500000];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  MergeSort(A,0,n);

  for(i = 0; i < n; i++){
    printf("%d",A[i]);
    if(i < n-1){
      printf(" ");
    }
  }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 4508
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

long long dist[204][204];

int main(){
  int N, M, R;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &R);
  std::vector<int > r(R);
  for (int i=0; i<R; i++){
    scanf("%d", &r[i]);
  }
  std::vector<int > A(M), B(M), C(M);
  std::vector<std::pair<int, int> > edge[204];
  for (int i=0; i<204; i++){
    for (int j=0; j<204; j++){
      dist[i][j]=1e18;
    }
    dist[i][i]=0;
  }
  for (int i=0; i<M; i++){
    scanf("%d", &A[i]);
    scanf("%d", &B[i]);
    scanf("%d", &C[i]);
    edge[A[i]].push_back(std::make_pair(B[i], C[i]));
    edge[B[i]].push_back(std::make_pair(A[i], C[i]));
    dist[A[i]][B[i]]=C[i];
    dist[B[i]][A[i]]=C[i];
  }
  for (int k=1; k<=N; k++){
    for (int i=1; i<=N; i++){
      for (int j=1; j<=N; j++){
	dist[i][j]=std::min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  /* for (int i=1; i<=N; i++){
    for (int j=1; j<=N; j++){
      printf("dist[%d][%d]=%lld\n", i, j, dist[i][j]);
    }
    }*/
  
  int array[R];
  std::sort(r.begin(), r.end());
  for (int i=0; i<R; i++){
    array[i]=r[i];
  }
  //printf("==========\n");
  long long ans = 1e18;
  do {
    long long d=0;
    bool ng=false;
    for (int i=0; i<R-1; i++){
      //printf("dist[%d][%d]=%lld\n", array[i], array[i+1], dist[array[i]][array[i+1]]);
      d += dist[array[i]][array[i+1]];
    }
    ans = std::min(ans, d);
  } while (std::next_permutation(array, array+R));
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;


ll dp[3010][3010];

int main(){
    rep(i,3010){
        rep(j,3010){
            dp[i][j] = 0;
        }
    }

    ll mod = 998244353;
    int n,s;
    cin >> n >> s;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    dp[0][0] = 1;

    rep(i,n){
        rep(j,s+1){
            dp[i+1][j] += 2*dp[i][j];
            dp[i+1][j] %= mod;
            if (j + a[i] <= s){
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= mod;
            }
        }
    }

    cout << dp[n][s] << endl;    
    return 0;
}


Measured memory_bytes: 74384
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        long n = scan.nextLong();


        long ans = b-1;
        if(ans > n) {
            ans = n;
        }
        long res = a * ans/b - a*(ans/b);
//        int[] seq = new int[n];
//        int[][] diff = new int[n][n];
//        int[][] score = new int[n][n];
//        for (int i=0;i<n;i++) {
//            int a = scan.nextInt();
//            int b = scan.nextInt();
//            int c = scan.nextInt();
//            int d = scan.nextInt();
//
//            //check score for [i,j], if curr_score>score, change c
//           if(d > score[a][b]) {
//               diff[a][b] = c;
//               score[a][b] = d;
//           }
//        }
//        seq[0] = 1;


//            for (int j=i+1;j<n;j++) {
//
//            }
//        }

        System.out.println(res);
//        for (int i = 0; i < t; i++) {
//            int x = scan.nextInt();
////            int res = scase(n);
////            System.out.println(res);
////            solveCase(i, x,y,s);
//        }
    }



//    static class Pair {
//        int a;
//        int b;
//    }


    static void solveCase(int t, int x, String s) {

    }


//    static int scase(int n) {
//
//    }

    public static void main(String[] args) {

//
        solve();

        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class Node {
//        int val;
//        Node next;
//        Node random;
//
//        public Node(int val) {
//            this.val = val;
//            this.next = null;
//            this.random = null;
//        }
//    }

//    static class Node {
//        int key;
//        int data;
//        Node next;
//        Node prev;
//
//        Node(int key, int data) {
//            this.key = key;
//            this.data = data;
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}


Measured memory_bytes: 26984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll ans = 0;
  rep(i, 4) {
    char c;
    cin >> c;
    if(c == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
# -*- coding: utf-8 -*-
n = int(input())
st = []
for i in range(n):
    s,t = input().split()
    st.append([s,int(t)])
x = input()

res = 0
flag = False
for i in range(n):
    s,t = st[i]
    if flag:
        res += t
    elif s==x:
        flag = True

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
ll mod = 998244353;
// ll mod = 1000000007;
  
ll mypow(ll number1,ll number2, ll mod){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,sum,a,b,c,d,e,h,q,p;
ll w, ans;
ll k;
ll x[500005], y[500005], z[500005];
string s, t;

void solve(){
    cin >> k >> n;
    ll sum = k;
    for(ll i=0;i<n;i++){
        cin >> x[i];
    }
    ll ans = 0;
    for(ll i=0;i<n;i++){
        ans = max(ans, x[i+1] - x[i]);
    }
    ans = max(ans, (x[0] + k - x[n-1]) % k);
    p(sum - ans);
    return;
}

int main(){
    // init();
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    ll q;
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        solve();
    }
    return 0;

}


















Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
inline void nl(){std::cout<<std::endl;}
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <typename T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <typename T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <typename T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}
//------------------------main function-------------------------------
void Main(){
    ll n , ans = 0, count = 1;
    cin >> n;
    priority_queue<multiset<char>> a;
    Rep(i, n){
        multiset<char> s;
        Rep(j, 10){
            char ff;
            cin >> ff;
            s.insert(ff);
        }
        a.push(s);
    }
    for (ll i = 1; i < n; i++) {
        multiset<char> b = a.top();
        a.pop();
        if(b == a.top()){
            count++;
        }else{
            ans += (count * (count - 1)) / 2;
            count = 1;
        }
    }
    ans += (count * (count - 1)) / 2;
    
    cout << ans << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    map<string, int> mp;
    int N;  cin >> N;
    for(int i = 0 ; i < N ; i++){
      string str;  cin >> str;
      mp[str] += 1;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
	return 0;
}

Measured memory_bytes: 3664
def main():
	N = int(input())
	a = list(map(int, input().split()))
	len_a = len(a)

	a.sort(reverse = True)

	Alice = sum(a[0 : len_a : 2])
	Bob = sum(a[1 : len_a : 2])

	print(Alice - Bob)

  
if __name__ == "__main__":
  	main()

Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

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

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<double>dp(n+1);
  auto tdp=dp;
  dp[0]=1;
  rep(i,n){
    double p;cin>>p;
    tdp.assign(n,0);
    rep(j,n){
      tdp[j+1]+=dp[j]*p;
      tdp[j]+=dp[j]*(1-p);
    }
    swap(dp,tdp);
  }
  double res=1;
  rep(i,n/2+1){
    res-=dp[i];
  }
  cout<<setprecision(12);
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
#include<map>
#include<queue>
using namespace std;

int cnt = 0;

int dfs(vector< pair<int, int> > p, vector<bool> b, vector<bool> f, int pos){
  bool ff = true;
  for(int i=0; i<f.size(); i++){
    if( !f[i] ){
      ff = false;
      break;
    }
  }
  if( ff ){
    cnt++;
    return 0;
  }

  for(int i=0; i<p.size(); i++){

    if( pos == p[i].first && !f[p[i].second] ){
      f[p[i].second] = true;
      dfs(p, b, f, p[i].second);
      f[p[i].second] = false;
    }
    if( pos == p[i].second && !f[p[i].first] ){
      f[p[i].first] = true;
      dfs(p, b, f, p[i].first);
      f[p[i].first] = false;
    }

  }

  return 0;
}


int main(){

  int n, m;
  cin >> n >> m;

  vector< pair<int, int> > p(m);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[i].first = a;
    p[i].second = b;
  }

  vector<bool> b(m, false);
  vector<bool> f(n, false);
  f[0] = true;

  dfs(p, b, f, 0);

  cout << cnt << endl;

  return 0;
}








// EOF


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;

int div(int N){
  if(N == 1 || N % 2 == 1) return 0;
  else return div(N/2) + 1;
}

int main(){

  int N,a,b,c=0; cin >> N;
  for (int i=1; i < N+1; i++) {
     a = div(i);
     if(b < a){
        b = a; c = i;
      }
   }
  if(N ==1 ) cout << 1 << endl;
  else cout << c  << endl;
  return 0;
}


Measured memory_bytes: 256
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**18
l = []
if x not in p:
  print(x)
else:
  for i in range(-1,102):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)

Measured memory_bytes: 9196
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    m = sq n
    k = until ((== 0) . (mod n)) pred m
    l = n `div` k
  print $ pred k + pred l

sq :: Int -> Int
-- sq n = sq' 1 . succ $ n
--   where
--     sq' i j | j == succ i = i
--             | m ^ 2 <= n = sq' m j
--             | otherwise = sq' i m
--       where
--         m = (i + j) `div` 2
sq = floor . sqrt . fromIntegral

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include<stdio.h>

char tui(char b)
{
  if(b=='A'){
    return 'T';
  }else if(b=='T'){
    return 'A';
  }else if(b=='G'){
    return 'C';
  }else{
    return 'G';
  }
}

int main(void)
{
  char b;
  scanf("%c",&b);
  
  printf("%c\n",tui(b));
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long ans = 0;
    for (int a = 1; a <= k; a++) {
      for (int b = 1; b <= k; b++) {
        for (int c= 1; c <= k; c++) {
          int temp = Main.gcd(a, b);
          ans += Main.gcd(temp, c);
        }
      }
    }
 
    System.out.println(ans);
  }

  private static int gcd (int a, int b) {
    if (b > a) {
      int x = a;
      a = b;
      b = x;
    }
    
    int temp;
    while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
  }

}

Measured memory_bytes: 27284