akhauriyash/Code-Regression huggingface dataset:
import math
from collections import defaultdict


def trial_division(n):
    factor = defaultdict(int)
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            factor[num] += 1
    factor[n] += 1
    if 1 not in factor.keys():
        factor[1] += 1
    return factor


a, b = map(int, input().split())
ans = 0
for i in trial_division(a).keys():
    if i in trial_division(b).keys():
        ans += 1
print(ans)

Measured memory_bytes: 3572
N,M =map(int,input().split())
a = abs(N-M)
mod = 10**9 + 7
n = 1
for i in range(N):
    n *= N-i
    n %= mod
m = 1
for i in range(M):
    m *= M-i
    m %= mod
if a > 1:
    print(0)
elif a == 1:
    print(n * m % mod)
else:
    print(n*m*2%mod)

Measured memory_bytes: 9052
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(void){
    int n;cin>>n;
    double tmp;
    double sum=0.0;
    rep(i,n){cin>>tmp;sum+=(1.0/tmp);}
    printf("%.12f\n", 1.0/sum);
}





Measured memory_bytes: 256
#include<iostream>
#include<map>
#include <vector>
using namespace std;


int main(){
    int n;
    bool ans=false;
    // vector<int>vt(9);
    // int even;
    const int NN =9;
    cin>>n;
    for (int i=1;i<=NN;i++){
        if (n % i ==0 && n / i <=9){
            ans=true;
            break;
        } 
    }
    if (ans){
        cout<< "Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    } 
    return 0;
}

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

int main(){
    int d,e;
    while(cin >> d >> e && d){
        double ans = 1e9;
        rep(i,110)rep(j,110){
            if(i+j == d){
                ans = min(ans, abs(e-sqrt(i*i+j*j)));
            }
        }
        printf("%.10lf\n", ans);
    }
}

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

int main(){
    char a[200010];
    scanf("%s",a);
    int cont1,cont2;
    for(int i=0;i<strlen(a);i++){
        if(a[i]=='A'){
            cont1=i;
            break;}
    }for(int i=strlen(a);i>=0;i--){
        if(a[i]=='Z'){
            cont2=i+1;
            break;
        }
    }
    printf("%d\n",cont2-cont1);
return 0;
}


Measured memory_bytes: 384
def solve():
    s=input().split()[0]
    cnt=[0]*2020
    cnt[0]=1
    m=0
    t=1
    for d in map(int,s[-1::-1]) :
        m=(m+d*t)%2019
        t=(t*10)%2019
        cnt[m]+=1
    return sum([ k*(k-1)//2 for k in cnt])

print(solve())


Measured memory_bytes: 9216
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
    }
    let mut l = 0;
    let mut r = 0;
    let mut cnt = 0;
    let mut res = vec![0; s.len()];

    loop {
        let mut edge = 0;
        while r <= s.len()- 2 {
            if &s[r..r+2] == &"RL".to_string() {
                edge = r;
            }
            if (&s[r..r+2] == &"LR".to_string()) {
                break
            }
            r += 1;
        }
        let acc_s = &s[l..r+1];
        let r_cnt = acc_s.chars().filter(|&c| c == 'R').count();
        let l_cnt = acc_s.chars().filter(|&c| c == 'L').count();
        if r_cnt %2 == 0 {
            res[edge+1] = (acc_s.len() + 1) / 2;
            res[edge] = acc_s.len() / 2;
        } else {
            res[edge] = (acc_s.len() + 1) / 2;
            res[edge+1] = acc_s.len() / 2;
        }
        l = r+1;
        r += 1;

        if r > s.len() -2 {
            break
        } 
    }
    for i in 0..s.len() {
        print!("{} ", res[i])
    }
    println!("");
}


Measured memory_bytes: 4604
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop  = do
  { [h, w] <- getInts
  ; if h == 0 && w == 0 then done
    else do
      { putStrLn $ unlines $ frame h w
      ; loop 
      }
  }

tedge :: Int -> String
tedge n = replicate n '#'

mbody :: Int -> String
mbody n = case n of
          0 -> ""
          1 -> "#"
          _ -> "#" ++ replicate (n-2) '.' ++ "#"

frame :: Int -> Int -> [String]
frame h w = case h of
          0 -> []
          1 -> [tedge w]
          _ -> [tedge w] ++ replicate (h-2) (mbody w) ++ [tedge w]
  

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn .unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""

done :: IO ()
done = return ()



Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdio.h>
#include <cmath>
#include <limits.h>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); ++i)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back


int n,x;
int main(void) {
    x = 2;
    for(cin>>n;n>=x;)x*=2;
    cout<<x/2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
pair<P,ll> p[114514];
ll par[214514];
ll ran[214514];
ll root(ll x){
	return par[x]==x?x:par[x]=root(par[x]);
}
void unite(ll x,ll y){
	x=root(x);
	y=root(y);
	if(x==y)return;
	if(ran[x]<ran[y])par[x]=y;
	else{
		par[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}
int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i].first.first>>p[i].first.second;
		p[i].second=i+1;
	}

	priority_queue<pair<ll,P>>que;
	sort(p,p+n);
	for(int i=1;i<n;i++){
		que.push({-p[i].first.first+p[i-1].first.first,{p[i].second,p[i-1].second}});
		swap(p[i-1].first.first,p[i-1].first.second);
	}
	swap(p[n-1].first.first,p[n-1].first.second);
	sort(p,p+n);
	for(int i=1;i<n;i++){
		que.push({-p[i].first.first+p[i-1].first.first,{p[i].second,p[i-1].second}});
		swap(p[i-1].first.first,p[i-1].first.second);
	}
	swap(p[n-1].first.first,p[n-1].first.second);

	for(int i=1;i<=n;i++)par[i]=i;
	ll ans=0;
	while(!que.empty()){
		pair<ll,P> x=que.top();
		que.pop();
		//cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
		if(root(x.second.first)!=root(x.second.second)){
			ans-=x.first;
			unite(x.second.first,x.second.second);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 12040
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let s: Vec<char> = buf.trim().chars().collect();

	let is_ac = s[0] == 'A'
	         && s[2..s.len()-1].iter().filter(|c| **c == 'C').count() == 1
	         && s[1].is_lowercase()
	         && s[2..].iter().all(|c| c.is_lowercase() || *c == 'C');

	if is_ac {
		println!("AC");
	} else {
		println!("WA");
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

ld R;

int main() {
    cin >> R;
    DOUBLE(6.28318530717958623200 * R);
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  float Sum = 0;
  float X[8],Y[8];
  int N;
  cin >> N;

  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i];
  }

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      float tmp = 0;
      tmp = sqrt(pow(X[i]-X[j],2)+pow(Y[i]-Y[j],2));
      Sum += tmp * 2;
    }
  }
  Sum = Sum/N;
  printf("%f",Sum);
  return 0;
}


Measured memory_bytes: 256
N,M,C = map(int, input().rstrip().split())
B = list(map(int, input().rstrip().split()))
A = [list(map(int, input().rstrip().split())) for _ in range(N)]
counter = 0
for i in A:
    res = [i[j]*B[j] for j in range(M)]
    answer = C + sum(res)
    if answer > 0:
        counter += 1

print(counter)

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

int main(void)
{
	int n;
	while(cin >> n && n != NULL)
	{
		int i = 1;
		int q;
		while(1)
		{
			q = (1+i)*i/2;
			if(q >= n)
				break;
			i++;
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//config = {stdin: 'tmp', newline: '\r\n'}; // win
config = {stdin: '/dev/stdin', newline: '\n'}; // linux

line = require('fs').readFileSync(config.stdin, 'ascii')
       .trim()
       .split(config.newline);

for (i = 0; line[i] !== '0'; i += 2)
  loop1(line[i + 1].split(' ').map(Number));

function loop1(ary) {
  var n = ary.length;
  var mean = ary.reduce(add, 0) / n;
  var div = ary.reduce(function (prev, cur) {
    return prev + (cur - mean) * (cur - mean);
  }, 0);
  console.log(Math.sqrt(div / n));
}

function add(a, b) { return a + b; }

Measured memory_bytes: 16076
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x,n,num,cnt = 0;
  vector <int> a;
  bool pos[110] = {0};
  cin >> x >> n;
  for(int i = 0; i < n; i++){
      cin >> num;
      pos[num] = 1;
  }
  for(int i = 0; i <= 105; i++){
      if(pos[i] == 0)
        a.push_back(i);
  }
  int ans = upper_bound(a.begin(),a.end(),x) - a.begin();
  if(a[ans] - x >= x - a[ans - 1]){
    ans--;
  }
  printf("%d\n",a[ans]);
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
using namespace std;
int main()
{
	double w[50];
	string k[50];
	int i = 0;
	while (cin >> w[i]) {
		i++;
	}
	for (int j = 0; j < i; j++) {
		if (w[j] <= 48.00) {
			k[j] = "light fly";

		}
		else if ((w[j] > 48.00) && (w[j] <= 51.00)) {
			k[j] = "fly";
		}
		else if ((w[j] > 51.00) && (w[j] <= 54.00)) {
			k[j] = "bantam";
		}
		else if ((w[j] > 54.00) && (w[j] <= 57.00)) {
			k[j] = "feather";
		}
		else if ((w[j] > 57.00) && (w[j] <= 60.00)) {
			k[j] = "light";
		}
		else if ((w[j] > 60.00) && (w[j] <= 64.00)) {
			k[j] = "light welter";
		}
		else if ((w[j] > 64.00) && (w[j] <= 69.00)) {
			k[j] = "welter";
		}
		else if ((w[j] > 69.00) && (w[j] <= 75.00)) {
			k[j] = "light middle";
		}
		else if ((w[j] > 75.00) && (w[j] <= 81.00)) {
			k[j] = "middle";

		}
		else if ((w[j] > 81.00) && (w[j] <= 91.00)) {
			k[j] = "light heavy";
		}
		else {
			k[j] = "heavy";
		}
		cout << k[j] << endl;
	}


	return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 4000;
int k, d;
V<int> ans;
void f(int a, int dd){
  ans.pb(a);
  if(!dd){
    if(!--k){
      for(int b:ans) cout << b;
      cout << endl;
      exit(0);
    }
  }else{
    FOR(i, max(0, a-1), min(10, a+2)) f(i, dd-1);
  }
  ans.pop_back();
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> k;
  while(true){
    FOR(i, 1, 10) f(i, d);
    d++;
  }
}

Measured memory_bytes: 3636
// =====================================================
//   File    :   main.cpp
//   Author  :   eezyl
//   Synopsis:   codeforces/atcoder template
//   Address :
//   Date    :   2020/08/15
// =====================================================

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

//#define rep(i, a, b) for (int i = (a); i < int(b); ++i)
typedef long long LL;

const int MOD = 1e9+7;

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

LL g[3005][3005] = {};
LL dp[3005][3005][4] = {};
void solve() {
    int R, C, K;
    cin >> R >> C >> K;
    for (int i = 0; i < K; ++i) {
        int r, c;
        LL v;
        cin >> r >> c >> v;
        g[r][c] = v;
    }
    for (int i = 1; i <= R; ++i) {
        for (int j = 1; j <= C; ++j) {
            for (int k = 0; k < 4; ++k)
                dp[i][j][k] = max(dp[i-1][j][k], dp[i][j-1][k]);
            if (g[i][j] != 0) {
                for (int k = 0; k < 4; ++k) {
                    dp[i][j][1] = max(dp[i][j][1], g[i][j] + dp[i-1][j][k]);
                }
                for (int k = 1; k < 4; ++k) {
                    dp[i][j][k] = max(dp[i][j][k], g[i][j] + dp[i][j-1][k-1]);
                }
            }
        }
    }
    LL ans = dp[R][C][0];
    for (int i = 1; i < 4; ++i)
        ans = max(ans, dp[R][C][i]);
    cout << ans << endl;
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//#define LOCAL
#ifdef LOCAL
freopen("data.in", "r", stdin);
while (!feof(stdin)) {
#endif // LOCAL

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

#ifdef LOCAL
}
printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif // LOCAL
    return 0;
}


Measured memory_bytes: 355652
#include<stdio.h>

#define MAX 2000000
int H, A[MAX+1];

void maxHeapify( int i )
{
  int l, r, largest, temp;

  l = 2 * i;
  r = 2 * i + 1;

  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;

  if( r <= H && A[r] > A[largest] ) largest = r;

  if( largest != i )
    {
      temp = A[i];
      A[i] = A[largest];
      A[largest] = temp;

      maxHeapify(largest);
    }
}

void buildMaxHeap()
{
  int i;

  for( i=H/2; i>0; i-- )
    {
      maxHeapify(i);
    }
}

int main()
{
  int i;

  scanf("%d", &H);

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

  buildMaxHeap();

  for( i=1; i<=H; i++ ) printf(" %d", A[i]);
  printf("\n");

  return 0;
}



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

int main()
{
	int n, s[100], i, max = 0, min = 1000, ave = 0;
	while(1)
	{
		cin >> n;
		if(n == 0){
			break;
		}
		for(i = 0; i < n; i++)
		{
			cin >> s[i];
			if(max < s[i]){
				max = s[i];
			}
			if(min > s[i]){
				min = s[i];
			}
		}
		
		for(i = 0; i < n; i++)
		{
			ave += s[i];
		}
		ave -= (max + min);
		ave /= (n - 2);
		
		cout << ave << endl;
		max = 0;
		min = 1000;
		ave = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
import numpy as np
[N, M, C] = list(map(int,input().split()))
B = np.array(list(map(int,input().split())))
ans = 0
for i in range(N):
    A = np.array(list(map(int,input().split())))
    if sum(A*B)+C > 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 12488
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + 11)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = list(map(int, input().split()))
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int d;

int f(int n){
  if(n==-1) return 0;
  return n/d+1;
}

int main(){
    int l, r;
    cin >> l >> r >> d;
    cout << f(r) - f(l-1) << endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    
    if( ( a * b)  % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N=1e2+5;
const int mod=1e9+7;
int dp[N][4][4];
int main()
{
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++)
    dp[2][j][k]=1;
    for(int i=2;i<=100;i++)
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++)
    {
        if(j==1&&(k==0||k==2)) dp[i+2][2][3]=(dp[i+2][2][3]+mod-dp[i][j][k])%mod;
        dp[i+1][k][0]=(dp[i+1][k][0]+dp[i][j][k])%mod;
        dp[i+1][k][1]=(dp[i+1][k][1]+dp[i][j][k])%mod;
        dp[i+1][k][2]=(dp[i+1][k][2]+dp[i][j][k])%mod;
        dp[i+1][k][3]=(dp[i+1][k][3]+dp[i][j][k])%mod;
        if(j==1&&k==2)
        {
            dp[i+1][k][3]=(dp[i+1][k][3]-dp[i][j][k]+mod)%mod;
            dp[i+2][0][3]=(dp[i+2][0][3]+mod-dp[i][j][k])%mod;
        }
        if(j==1&&k==3) dp[i+1][k][2]=(dp[i+1][k][2]-dp[i][j][k]+mod)%mod;
        if(j==2&&k==1) dp[i+1][k][3]=(dp[i+1][k][3]-dp[i][j][k]+mod)%mod;
    }
    int n;
    cin >> n;
    int ans=0;
    for(int j=0;j<4;j++)
    for(int k=0;k<4;k++) ans=(ans+dp[n][j][k])%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#define ABS(a) ((a)<0?(-(a)):(a))


int main()
{
    long long i,j,memo=-1,n;
    scanf("%lld", &n);
    if(n==0){
        printf("0\n");
        return 0;
    }
    while(n!=0){
        if(n>0){
            for(i=1,j=0;i<n;i|=i<<2,j+=2);
            n-=(long long)1<<j;
        }else{
            for(i=2,j=1;i<ABS(n);i|=i<<2,j+=2);
            n+=(long long)1<<j;
        }
        if(memo!=-1)for(i=memo-1;i>j;i--)printf("0");
        printf("1");
        memo=j;
    }
    for(i=memo-1;i>=0;i--)printf("0");
    printf("\n");
    return 0;
}


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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r1 = ReadSplit();
            var n = r1[0].Long();
            var m = r1[1].Long();
            var hl = new long[n];
            var rh = ReadSplit();
            for (int i = 0; i < n; i++)
            {
                hl[i] = rh[i].Long();
            }
            var l = new long[n];
            
            for (int i = 0; i < m; i++)
            {
                var r2 = ReadSplit();
                var a = r2[0].Long();
                var b = r2[1].Long();
                if (hl[a - 1] > hl[b - 1])
                {
                    l[b - 1] = 1;
                }
                else
                {
                    l[a - 1] = 1;
                }
                if (hl[a - 1] == hl[b - 1])
                {
                    l[a - 1] = 1;
                    l[b - 1] = 1;
                }
            }

            WriteRead(l.Where(x => x == 0).Count());
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



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

using namespace std;

int main()
{
  char b;
  cin >> b;

  switch (b)
  {
  case 'A':
    cout << 'T' << endl;
    break;
  case 'T':
    cout << 'A' << endl;
    break;
  case 'C':
    cout << 'G' << endl;
    break;
  case 'G':
    cout << 'C' << endl;
    break;
  }
}

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

long long ara[100009],tra[300009];

int main()
{


        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,z=0,cnt=0,res=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld %lld",&n,&d,&m);

        f=d; ara[f]++; ans=f; if(n==1){  flg=1; }

        if(flg==0)
        {

            for(i=2;i<=400007;i++)
            {
                b=f*f;

                c=b%m; ara[c]++; if(ara[c]==3){  z=i; break;   }

                ans=ans+c; if(i==n){  flg=1; break;  }

                if(ara[c]==2 && x==0){  x=i;  }

                if(x!=0)
                {
                    sum=sum+c; y++;  tra[y]=sum;

                }



                f=c;

            }

        }


        if(flg==0)
        {
            fr=z-x; sc=n-z; sc++;

            tr=sc/fr; p=tra[y]*tr; ans=ans+p;

            h=sc%fr; ans=ans+tra[h];

        }



        printf("%lld\n",ans);







    return 0;
}





Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M, S, T;
    cin >> N >> M;
    using P = pair<int, int>;
    vector<P> edge;
    vector<vector<int>> g(N, vector<int>(N, 0));
    for (int i = 0, u, v; i < M; i++) { (cin >> u >> v), edge.push_back({u - 1, v - 1}), g[u - 1][v - 1] = g[v - 1][u - 1] = 1; }
    cin >> S >> T;
    S--, T--;
    vector<bool> used(N, false);
    auto dfs = [&](auto&& self, const int s, const int f) -> int {
        if (s == T) { return f; }
        used[s] = true;
        for (int i = 0; i < N; i++) {
            if (used[i] or g[s][i] == 0) { continue; }
            const int d = self(self, i, min(f, g[s][i]));
            if (d == 0) { continue; }
            return g[s][i] -= d, g[i][s] += d, d;
        }
        return 0;
    };
    int flow = 0;
    while (true) {
        fill(used.begin(), used.end(), false);
        const int f = dfs(dfs, S, 1 << 30);
        if (f == 0) { break; }
        flow += f;
    }
    cout << flow << endl;
    vector<int> ans;
    for (int i = 0; i < M; i++) {
        const int u = edge[i].first, v = edge[i].second;
        if (g[u][v] == 2) { ans.push_back(i); }
    }
    cout << ans.size() << endl;
    for (const int a : ans) { cout << a + 1 << endl; }
    return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

int main () {
  int w, h, n;
  cin >> w >> h >> n;
  // 1max2min3max4min
  int xl = 0, xr = w, yd = 0, yu = h;
  rep(i,n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) xl = max(xl, x);
    else if (a == 2) xr = min(xr, x);
    else if (a == 3) yd = max(yd, y);
    else yu = min(yu,y);
  }

  int ans = max(0, xr-xl)*max(0, yu-yd);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$N = $sc->nextInt();
$K = $sc->nextInt();
$array = [];
$sum = 0;

for($i=0;$i<$N;$i++){
    $array[] = $sc->nextInt();
}

sort($array);

for($i=0;$i<$K;$i++){
    $sum += $array[$i];
}

echo $sum.PHP_EOL;


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

int main() {
    long long k,n;
    cin >> k >> n;
    long long a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    long long d[n];
    d[0]=a[0]+k-a[n-1];
    for(int i=1;i<n;i++){
        d[i]=a[i]-a[i-1];
    }
    sort(d,d+n);
    cout << k-d[n-1] << endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
  int N;
  cin>>N;
  vector<int>B(N-1);
  vector<int>A(N);
  for(int i=0;i<N-1;i++){
    cin>>B[i];
  }
  int sum=0;
  A[0]=B[0];
  A[N-1]=B[N-2];
  for(int i=0;i<N-2;i++){
    A[i+1]=min(B[i],B[i+1]);
    sum+=A[i];
  }
  sum+=A[N-1]+A[N-2];
  cout<<sum<<endl;
  

  return 0;}

Measured memory_bytes: 256
using System;

namespace B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var s = Console.ReadLine().ToCharArray();
			var t = Console.ReadLine().ToCharArray();
			Array.Sort(s);
			Array.Sort(t);
			Array.Reverse(t);
			Console.WriteLine(string.Compare(new string(s), new string(t)) >= 0 ? "No" : "Yes");
		}
	}
}

Measured memory_bytes: 13524
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]
inf = 10**9
def dfs(cur,a,b,c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf
    ret0 = dfs(cur+1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c) + 10
    ret2 = dfs(cur+1,a,b+l[cur],c) + 10
    ret3 = dfs(cur+1,a,b,c+l[cur]) + 10
    
    return min(ret0,ret1,ret2,ret3)
 
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
N = int(input())
dp = [[] for _ in range(N+1)]
dp[1] = [["a"]]
for i in range(2,N+1):
    for j in range(len(dp[i-1])):
        for k in range(len(set(dp[i-1][j]))+1):
            dp[i].append(dp[i-1][j]+[chr(97+k)])
ans = dp[N]
for i in range(len(ans)):
    print("".join(ans[i]))

Measured memory_bytes: 27460
import java.util.*;
import java.io.*;

/*
 * E - Knapsack 1
 */
public class Main
{

public static void main( String[] args ) throws Exception
{
	final Scanner sc = new Scanner( System.in );// new FileInputStream( "1" ) );
	final int N = sc.nextInt();//総アイテム数
	final int W = sc.nextInt();//最大積載量

	final long[] wArray = new long[ N ];
	final long[] vArray = new long[ N ];

	for( int i = 0; i < N; ++i )
	{
		wArray[ i ] = sc.nextLong();
		vArray[ i ] = sc.nextLong();
	}

	final Map< Long, Long > weightValueMap = new HashMap<>( 1000 );
	//final Map< Long, List< Integer > > weightItemListMap = new HashMap<>( 1000 );// wをキー,それを構成するアイテムのiのリストを値とする

	for( int i = 0; i < N; ++i )
	{
		final long w = wArray[ i ];
		final long v = vArray[ i ];

		//キャッシュしているすべてのwに対して組み合わせを計算する

		Map< Long, Long > update = new HashMap<>();
		final Map< Long, List< Integer > > update2 = new HashMap<>();
		for( Map.Entry< Long, Long > entry : weightValueMap.entrySet() )
		{
			final long cachedWeight = entry.getKey();
			final long cachedValue = entry.getValue();
			final long newWeight = cachedWeight + w;
			final long newValue = cachedValue + v;
			if( newWeight <= W )
			{
				final boolean isBetter = isBetter( weightValueMap, newWeight, newValue );
				if( isBetter )
				{
					update.put( newWeight, newValue );
					/*
					List< Integer > itemList = weightItemListMap.get( newWeight );
					if( itemList == null )
					{
						itemList = new ArrayList<>();
						update2.put( newWeight, itemList );
					}
					itemList.addAll( weightItemListMap.get( cachedWeight ) );
					itemList.add( i );
					*/
				}
			}
		}

		weightValueMap.putAll( update );

		clean( weightValueMap );
		//weightItemListMap.putAll( update2 );

		//このアイテム単体について処理
		if( w <= W )
		{
			final boolean isBetter = isBetter( weightValueMap, w, v );
			if( isBetter )
			{
				weightValueMap.put( w, v );
				/*
				List< Integer > itemList = weightItemListMap.get( w );
				if( itemList == null )
				{
					itemList = new ArrayList<>();
					weightItemListMap.put( w, itemList );
				}
				itemList.add( i );
				*/
			}
		}

		weightValueMap.putAll( update );
	}

	//答えを求める
	long max = 0;
	for( Map.Entry< Long, Long > entry : weightValueMap.entrySet() )
	{
		final long v = entry.getValue();
		if( v > max )
		{
			max = v;
		}
	}
	p( max );
}

public static void clean( final Map< Long, Long > weightValueMap )
{
	//重さが高く、価値が低い情報を削除する
	final TreeSet< Long > weightSet = new TreeSet< Long >();
	weightSet.addAll( weightValueMap.keySet() );
	long maxValue = 0;
	for( Long weight : weightSet )
	{
		long value = weightValueMap.get( weight );
		if( value < maxValue )
		{
			weightValueMap.remove( weight );
		}
		else
		{
			maxValue = value;
		}
	}
}

public static boolean isBetter( final Map< Long, Long > weightValueMap, final long w, final long v )
{
	final Long cachedValue = weightValueMap.get( w );
	if( cachedValue == null || cachedValue < v )
	{
		return true;
	}
	else
	{
		return false;
	}
}

public static void p( Object o )
{
	System.out.println( o );
}

}

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

int n, a[100005];
long long b, tot, ans;

int main() {
    cin >> n;
    for (int i = 0; i <= n; i++){
        cin >> a[i];
        tot += a[i];
    }
    b = 1;
    bool flag = true;
    for (int i = 0; i <= n; i++){
        if (b < a[i]){
            flag = false;
            break;
        }
        ans += b;
        b -= a[i];
        tot -= a[i];
        b = min(b*2, tot);
    }
    if (!flag) cout << -1 << "\n";
    else cout << ans << "\n";
}


Measured memory_bytes: 4032
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        writer.println(n*n*n);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(void) {
	ll n, k;
	cin >> n >> k;
	vector<vector<ll> > v(2, vector<ll>());
	rep(i, 0, n) {
		ll a;
		cin >> a;
		if (a == 0)k--;
		else if (a > 0)v[0].pb(a);
		else v[1].pb(-a);
	}
	sort(all(v[0]));
	sort(all(v[1]));
	if (k <= 0) {
		cout << 0 << endl;
		return 0;
	}
	ll mn = 1000000000000000000LL;
	rep(i, 0, 2) {
		ll a = i;
		ll b = 1 - i;
		if (v[a].sz == 0) {
			mn = min(mn, v[b][k-1]);
		}
		rep(j, 0, v[a].sz) {
			if (k - j - 2 >= 0 && k - j - 2 < v[b].sz)mn = min(mn, v[a][j] * 2 + v[b][k - j - 2]);
		}
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define sortV(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
// DSU
/*
const int maxn=100009;
int arr[maxn];
int sz[maxn];
void init(){rep(i,maxn){arr[i]=i;sz[i]=1;}}
int root(int a){while(a!=arr[a]){arr[a]=arr[arr[a]];a=arr[a];}return a;}
int check(int a,int b){if(root(a)==root(b))return 1;return 0;}
int un(int a,int b)
{
  int roota=root(a);int rootb=root(b);
  if(sz[roota]>=sz[rootb]){sz[roota]+=sz[rootb];arr[rootb]=roota;}
  else {sz[rootb]+=sz[roota];arr[roota]=rootb;}
}
*/

//Dijkstra
/*
const int maxn=0x3f3f3f3f;
void dijkstra(int n,int dist[],vector<pi >adj[],int s)
{
  int visited[n+1];
  repre(i,0,n)
  {
    visited[i]=0;
    dist[i]=maxn;
  }
  dist[s]=0;
  priority_queue<pi ,vector<pi>,greater<pi> >p;
  p.push(mkp(0,s));
  while(p.empty()==false)
  {
    pi temp=p.top();
    p.pop();
    if(visited[temp.ss])continue;
    visited[temp.ss]=1;
    int u=temp.ss;
    rep(i,adj[u].size())
    {
      if(dist[u]+adj[u][i].ss<dist[adj[u][i].ff])
      {
        dist[adj[u][i].ff]=dist[u]+adj[u][i].ss;
        p.push(mkp(dist[adj[u][i].ff],adj[u][i].ff));
      }
    }
  }
}*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n;
  cin>>n;
  unordered_map<string,int>mp;
  int ans=0;
  rep(i,n)
  {
    string s;
    cin>>s;
    sort(sortV(s));
    mp[s]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++)
  {
    int temp=it->second;
    ans+=(temp*(temp-1))/2;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 10660
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,i,j,k,l;
	cin>>n;
	map<string,ll> m;
	while(n--)
	{
		string str;
		cin>>str;
		m[str]++;
	}
	map<string,ll>::iterator it;
	k=0;
	for(it=m.begin();it!=m.end();it++)
	{
		if(it->second>k)
			k=it->second;
	}
	for(it=m.begin();it!=m.end();it++)
	{
		if(it->second==k)
			cout<<it->first<<"\n";
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<long long> a(n*3);
	for (int i = 0; i < n*3; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<long long>());

	long long res = 0;
	for (int i = 1; i < n*2; i = i + 2) {
		res += a[i];
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 5608
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<ll> A(n);
    map<ll, int>C;
    rep(i, n){
        cin >> A[i];
        C[A[i]]++;
    }
    sort(all(A), greater<ll>());
    ll res = 0;
    rep(i, n){
        ll tmp = 1;
        while(1){
            if(tmp>A[i])break;
            tmp *= 2;
        }
        ll num = tmp - A[i];
        if(A[i] != num && C[A[i]] && C[num] || A[i] == num && C[num]>1){
            res++;
            C[num]--;
            C[A[i]]--;
        }
    }
    cout << res << ln;

}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n ;
    cin >> n ;
    ll ans = 0 ;
    for(ll i=1;i<=n;i++){
        ans += i*(n/i)*(n/i+1)/2 ;
    }
    cout << ans <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3572
#include <cstdio>

int read() {
    int x = 0, f = 1; char s;
    while((s = getchar()) < '0' || s > '9') if(s == '-') f = -1;
    while(s >= '0' && s <= '9') {x = (x << 1) + (x << 3) + (s ^ 48); s = getchar();}
    return x * f;
}

int main() {
    char ch[10];
    scanf("%s", ch);
    if(ch[1] == 'R') ch[1] = 'B';
    else ch[1] = 'R';
    puts(ch);
    return 0;
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
  int r,g,b,n, ans = 0;
  cin >> r >> g >> b >> n;

  REP (i, (n / r) + 1) {
    REP (j, (n / g) + 1) {
      int sum = i * r + j * g;
      if (n < sum) break;
      if (n == sum) ans++;
      else if (n - sum < b ^ 2 && (n - sum) % b == 0) ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k;
long long a[1000001],kq[10000001],mi;
int main()
{
    cin>>n>>k;
    for(long i=1;i<=n;i++)
        cin>>a[i];
    for(long i=1;i<=k;i++)
        kq[i]=abs(a[i]-a[1]);
    for(long i=k+1;i<=n;i++)
    {
        mi=1e9;
        for(long j=i-k;j<=i-1;j++)
            mi=min(abs(a[i]-a[j])+kq[j],mi);
        kq[i]=mi;
    }
    cout<<kq[n];
}


Measured memory_bytes: 3072