akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string dream[] = {"dream", "dreamer", "erase", "eraser"};
  string s;
  cin >> s;

  int n = s.size();
  // dp[x+1] := x文字目までを構成できるか
  vector<bool> dp(n + 10, false);
  dp[0] = true;

  for (int i = 0; i < n; i++) {
    if (!dp[i]) {
      continue;
    }
    if (s.substr(i, 5) == "dream") {
      dp[i + 5] = true;
    }
    if (s.substr(i, 7) == "dreamer") {
      dp[i + 7] = true;
    }
    if (s.substr(i, 5) == "erase") {
      dp[i + 5] = true;
    }
    if (s.substr(i, 6) == "eraser") {
      dp[i + 6] = true;
    }
  }
  cout << (dp[n] ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 512
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn yakusu(n: i64) -> Vec<i64> {
    let mut a = vec![];
    let mut b = vec![];
    for i in 1..n {
        if i * i > n { break }
        if n % i == 0 {
            a.push(i);
            if i * i < n { b.push(n / i); }
        }
    }
    b.iter().chain(a.iter().rev()).map(|&x| x).collect()
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: i64 = sc.cin();
    let xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();

    for &p in yakusu(xs.iter().sum()).iter() {
        let mut rs: Vec<i64> = xs.iter().map(|&x| x % p).filter(|&r| r > 0).collect();
        rs.sort();
        let mut st: i64 = 0;
        let mut ue: i64 = rs.iter().map(|&r| p - r).sum();
        let mut a = k + 1;
        if (st - ue).abs() % p == 0 {
            a = min!(a, max!(st, ue));
        }
        for &r in rs.iter() {
            st += r;
            ue -= p - r;
            if (st - ue).abs() % p == 0 {
                a = min!(a, max!(st, ue));
            }
        }
        if a <= k {
            put!(p);
            return;
        }
    }
    put!(1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(si,h)rep(sj,w) {
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j)); // .emplace(i,j)
        };
        update(si,sj,0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir,4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if (ni<0||ni>=h||nj<0||nj>=w) continue;
                if (s[ni][nj] == '#') continue;
                update(ni,nj,dist[i][j]+1);
            }
        }
        rep(i,h)rep(j,w) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

int main() {
    
    int A, B, C, D, L, R;
    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;
    
    if (L > R){
        cout << "Left" << endl;
    } else if (L < R){
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mxn=2e5+5;

int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n],i;
	for(i=0;i<n;i++) 
		cin>>a[i];
	sort(a,a+n);
	ll s=0;
	for(i=0;i<k;i++)
		s+=a[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d %d",&a,&b);
	double e = (double)a/(double)b;
	c = a/b;
	d = a%b;	
	printf("%d %d %lf\n",c,d,e);
	
	return 0;
}

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

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);
    int A, B, C;
    while(cin>>A>>B>>C){
        vector<int> vt;
        vt.push_back(A);
        vt.push_back(B);
        vt.push_back(C);
        sort(vt.begin(), vt.end());
        cout<<vt[0]+vt[1]<<endl;
        vt.clear();
    }
	return 0;
}



Measured memory_bytes: 384
N = int(input())
A = [int(i)-1 for i in input().split()]

from collections import defaultdict

flag = [True] * N

cnt = 0
for i in range(N):
    if flag[A[i]] and flag[i] and A[A[i]] == i:
        cnt += 1
        flag[A[i]] = False
        flag[i] = False

print(cnt)

Measured memory_bytes: 13880
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <map>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	ll n,m;
	map<string,int> mymap;
	cin>>n;
	string temp;
	ll max=0;
	for(ll i=0;i<n;i++){
		cin>>temp;
		mymap[temp]++;
	}
	cin>>m;
	for(ll i=0;i<m;i++){
		cin>>temp;
		mymap[temp]--;
	}
	map<string,int>::iterator it;
	for(it=mymap.begin();it!=mymap.end();it++){
		if(it->second>max){
			max=it->second;
		}
	}
	cout<<max<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    static int count = 0;
    static int n;
    static int m;
    static boolean[][] a;
    static boolean[] visit;
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new boolean[n+1][n+1];
        visit = new boolean[n+1];
        visit[1] = true;
        for(int i = 0; i < m; i++){
            int p = sc.nextInt();
            int q = sc.nextInt();
            a[p][q] = a[q][p] = true;
        }
        dfs(1);
        System.out.println(count);
    }

    static void dfs(int v){
        boolean all_visit = true;
        for(int i = 1; i < n+1; i++){
            if(visit[i] == false){
                all_visit = false;
                break;
            }
        }

        if(all_visit){
            count++;
        }

        for(int i = 1; i < n+1; i++){
//            System.out.println(i + " : " + visit[i]);
            if(a[v][i] && visit[i] == false){
                visit[i] = true;
//                System.out.println(v + " : " + i);
                dfs(i);
                visit[i] = false;
            }
        }
    }
}

Measured memory_bytes: 21844
// finish date: 2018/03/04

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>

vi memo;
int D;
map<int, pii > mp;

int memo_dfs(int i) {
    if (i - D <= 0) {
        memo[i] = 0;
        return 0;
    }
    if (memo[i] != INF) return memo[i];
    pii pair1 = mp[i];
    pii pair2 = mp[i - D];
    memo[i] = abs(pair1.first - pair2.first) + abs(pair1.second - pair2.second);
    memo[i] += memo_dfs(i - D);
    return memo[i];
}


int main() {
    int H, W;
    cin >> H >> W >> D;
    memo = vi(H * W + 1, INF);

    int in;
    FOR(i, 1, H + 1) {
        FOR(j, 1, W + 1) {
            cin >> in;
            mp[in] = pii(i, j);
        }
    }
    rep(i, H * W + 1) {
        memo_dfs(i);
    }
    int Q;
    cin >> Q;
    rep(i, Q) {
        int sum = 0;
        int L, R;
        cin >> L >> R;
//        while (L != R) {
//            pii pair1 = mp[L];
//            L += D;
//            pii pair2 = mp[L];
//            sum += abs(pair1.first - pair2.first) + abs(pair1.second - pair2.second);
//        }
//        cout << sum << endl;
        cout << memo[R] - memo[L] << endl;
    }
    return 0;
}





Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

typedef long long lint;
int main(){
    long double x, y, z;
    long double l;
    cin >> l;
    x = l / 3;
    cout << fixed << setprecision(10) << x*x*x << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Control.Monad

main = do
    [a,b,k] <- map read.words <$> getLine :: IO [Int]
    mapM_ f (calc a b k)

f c = putStrLn c
calc a b k = nub $ map show ([a..(min (a+k-1) b)] ++[(max (b-k+1) a)..b])

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

ll mod = 1e9+7;

int main()
{
    ll n, ans=1, stock=0;
    string s;
    cin>>n>>s;
    for (ll i = 0; i < 2*n; i++)
    {
        if((s[i]=='B' && i%2==0) || (s[i]=='W' && i%2==1) )   //fuyasu
        {
            stock++;
        }
        else //herasu
        {
            ans*=stock;
            ans%=mod;
            stock--;
        }
    }
    if(stock!=0) ans=0;
    for (ll i = 1; i <= n; i++)
    {
        ans*=i;
        ans%=mod;
    }
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
  int x, y;
  int d[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  cin >> x >> y;
  cout << ((d[x - 1] == d[y - 1]) ? "Yes" : "No") << endl;
  return 0;
}


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

int main(void)
{
	int n, i;
	while (cin >> n, n){
		vector <int> v(32);
		v[0] = n;
		while (1){
			int cnt = 0;
			for (i = 0; v[i] != 0; i++){
				cout << v[i];
				if (v[i + 1] == 0) puts("");
				else cout << " ";
			}
			if (v[0] == 1) break;
			for (i = 32; 0 <= i; i--){
				if (v[i] == 0) continue;
				if (v[i] == 1) {
					// 1ツづ個青板づーツつゥツつシツつヲツづゥ
					v[i] = 0;
					cnt++;
					continue;
				}
				// 1ツつカツづ。ツづ按つ「ツつゥツつクツづ個鳴鳴氾カツ個クツづァツつオツづづ板づェツーツつュ
				v[i]--;
				cnt++;
				break;
			}
			// 1ツつカツづ。ツづ按つ「ツつゥツつクツづ個鳴鳴氾カツづ個篠淞つゥツづァツつイツづ可づ・
			for (int j = i + 1; 0 < cnt; j++){
				v[j] = min(cnt, v[i]);
				cnt -= v[i];
			}
		}
	}
	
	return 0;
}

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

int N;
int A, B, C, D;
string S;
int consecutiverocks=0;
int consecutiveblanks=0;

int main()
{
    cin>>N>>A>>B>>C>>D;
    cin>>S;

    for (int i=A-1; i<=C-1; i++)
    {
        if (S[i]!='#')
        {
            consecutiverocks=0;
        }

        else if (S[i]=='#')
        {
            consecutiverocks++;
        }

        if (consecutiverocks==2)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }  

    for (int i=B-1; i<=D-1; i++)
    {
        if (S[i]!='#')
        {
            consecutiverocks=0;
        }

        else if (S[i]=='#')
        {
            consecutiverocks++;
        }

        if (consecutiverocks==2)
        {
            cout<<"No"<<endl;
            return 0;
        }
    } 

    if (A<B && B<C && C<D)
    {
        cout<<"Yes"<<endl;
        return 0;
    }

    else if (A<C && C<B && B<D)
    {
        cout<<"Yes"<<endl;
        return 0;
    }

    else if (A<B && B<D && D<C)
    {
        for (int i=B-2; i<=D; i++)
        {
            if (S[i]=='.')
            {
                consecutiveblanks++;
            }

            else if (S[i]=='#')
            {
                consecutiveblanks=0;
            }

            if (consecutiveblanks==3)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define RFOR(i,k,n) for (int (i)=(n)-1; (i)>=(k); --(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
using namespace std;

int main() {
  int N, A;
  cin >> N;
  set<int> S;
  REP(i, N) {
    cin >> A;
    if(S.erase(A) == 0) { S.insert(A); }
  }
  cout << S.size() << endl;
  return 0;
}


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

long long x;

bool isPrime(long long n)
{
    bool prime = true;
    for (long long i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            prime = false;
        }
    }
    return prime;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> x;
    while (true)
    {
        if (isPrime(x))
        {
            cout << x;
            cin >> x;
            return 0;
        }
        x++;
    }
}

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

int main(void){
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    int A, B;
    cin >> A >> B;
    int a, b, c, d;
    double time{0};
    int sum{0};

    while(true){
        sum=0;
        for(int i{A}; i<=B; ++i){
            a = i/10000;
            b = i/1000%10;
            c = i/10%10;
            d = i%10;
            if(a==d and b==c)
                ++sum;
        }
        end  = chrono::system_clock::now();
        time =  static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
        if(time>1998)
            break;
    }
    cout << sum << endl;

}


Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
	int i,j,n,temp,count;
	int a[100];
	int flag = 1;

	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
        i = 0;
	count = 0;
	while(flag){
		flag = 0;
		for(j = n - 1;j > i;j--){
			if(a[j] < a[j - 1]){
				temp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = temp;
				flag = 1;
				count++;
			}
		}
		i++;
	}
	for(i = 0;i < n;i++){
		if(i != 0 && i < n)printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	printf("%d\n",count);
        return 0;
}

Measured memory_bytes: 604
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

#include <set>

typedef vector<string> vs;

bool ok(string s){
    rep(i,s.size()/2) if(s[i]!=s[s.size()-1-i]) return false;
    return true;
}

int main(){
    string line;
    while(getline(cin,line)){
        string s;
        for(char c : line) if(isalpha(c)) s += toupper(c);
        vs cand;
        int n=s.size();
        for(int i=n;i>=3;i--){
            rep(j,n-i+1){
                if(ok(s.substr(j,i))) cand.eb(s.begin()+j, s.begin()+j+i);
            }
        }
        bool used[1111]={};
        rep(j,cand.size()){
            rep(i,j){
                int diff=abs((int)cand[j].size()-(int)cand[i].size());
                diff/=2;
                if(cand[i].size()<cand[j].size()){
                    if(cand[j].substr(diff,cand[i].size())==cand[i]) used[i]=true;
                }
                else{
                    if(cand[i].substr(diff,cand[j].size())==cand[j]){
                        used[j]=true;
                    }
                }
            }
        }
        vs ans;
        rep(i,cand.size()) if(!used[i]) ans.eb(cand[i]);
        rep(i,ans.size()){
            cout << ans[i];
            if(i+1!=(int)ans.size()) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1220
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split(' ')))

ans = []
for i in range(N):
  if i == 0:
    ans.append(0)
  else:
    h = A[i-1] - A[i]
    if h < 0:
      ans.append(0)
    else:
      ans.append(h)
      A[i] += h

print(sum(ans))


Measured memory_bytes: 32204
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int arr[100];

int main()
{
	int n;
	cin >> n;
	int ct = 0;
	for (int i = 1; i<=n; i++)
		cin >> arr[i];
	for (int i = 2; i<n; i++)
	{
		int ok = 0;
		if (arr[i] > arr[i-1])
			ok++;
		if (arr[i] > arr[i+1])
			ok++;
		if (ok == 1)
			ct++;
	}
	cout << ct;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main(){
  ll H,W,K,i,j,comb,k;scanf("%lld%lld%lld",&H,&W,&K);K--;
  ll dp[H+1][W];memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  bool ok;
  for(i=0;i<H;i++){
    for(comb=0;comb<(1<<(W-1));comb++){
      bitset<7> C(comb);ok = true;
      for(j=0;j<W-2;j++) ok &= !(C[j] && C[j+1]);
      if(ok){
        for(j=0;j<W;j++){
          if(j<W-1 && C[j]) dp[i+1][j+1] += dp[i][j];
          else if(j>0 && C[j-1]) dp[i+1][j-1] += dp[i][j];
          else dp[i+1][j] += dp[i][j];
        }
        for(j=0;j<W;j++) dp[i+1][j] %= mod;
      }
    }
  }
  printf("%lld\n",dp[H][K]);
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};

const int len = 50;
ll N, K;
ll A[100000];
vector<int> X;
ll dp[len + 1][2];

ll solve(){
    REP(i, len + 1) REP(j, 2) dp[i][j] = -1;
    dp[0][0] = 0;
    REP(i, len){
        int zero = 0, one = 0;
        REP(j, N){
            if((A[j] >> len - 1 - i) & 1 == 1) zero++;
            else one++;
        }
        if(dp[i][0] != -1){
            if(X[i] == 1){
                dp[i + 1][0] = max(dp[i + 1][0], 2 * dp[i][0] + one);
                dp[i + 1][1] = max(dp[i + 1][1], 2 * dp[i][0] + zero);
            }else{
                dp[i + 1][0] = max(dp[i + 1][0], 2 * dp[i][0] + zero);
            }
        }
        if(dp[i][1] != -1){
            dp[i + 1][1] = max(dp[i + 1][1], 2 * dp[i][1] + max(zero, one));
        }
    }
    return max(dp[len][0], dp[len][1]);
}

signed main(){
    cin >> N >> K;
    REP(i, N) cin >> A[i];
    REP(i, len) X.push_back((K >> len - 1 - i) & 1);
    PRINT(solve());
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int dp[2050]; 
int main() {
	int s;
	cin >> s;
	dp[0] = 1;
	for (int i = 3; i <= s; i++)
	{
		dp[i] = dp[i-1] + dp[i-3];
		dp[i] %= MOD;
	}
	
	cout << dp[s] << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int N, M, x;
	cin >> N >> M >> x;

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

	int ret = 0x3f3f3f3f;
	for (int i = 1; i < 1 << N; ++i) {
		int sum[12]{}, money = 0;
		for (int j = 0; j < N; ++j) if (i & 1 << j) {
			money += C[j];
			for (int k = 0; k < M; ++k) {
				sum[k] += arr[j][k];
			}
		}

		bool flg = 1;
		for (int j = 0; j < M; ++j) {
			if (sum[j] < x) {
				flg = 0;
				break;
			}
		}

		if (flg) ret = min(ret, money);
	}

	if (ret == 0x3f3f3f3f) cout << -1;
	else cout << ret;

	return 0;
}

Measured memory_bytes: 3648
R,G,B=map(int,input().split())
K=int(input())


for i in range (K+1):
    if R < G < B:
        print ('Yes')
        exit()
    else:
        pass
    
    if G < B:
        pass
    else:
        B*=2
        continue

    if R < G:
        pass
    else:
        G*=2
        continue

print('No')


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

int main()
{
  long long n;
  cin >>n;
  vector<int>a(n-1);
  long long sum=0;
  for(int i=0;i<n-1;i++){
    cin>>a[i];
  }
  map<int,int>mp;
  for(int x:a){
    if(mp.count(x)){
      mp.at(x)++;
    }else{
      mp[x]=1;
    }
  }
  vector<int>shain(n+1);
  for(int i=0;i<n;i++){
    shain[i]=0;
  }  
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    shain[iter->first]=iter->second;
  }
  for(int i=1;i<n+1;i++){
    cout<<shain[i]<<endl;
  }  
  return 0;  
}

Measured memory_bytes: 14284
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int H, W, h, w;    
    cin >> H >> W;
    cin >> h >> w;

    cout << (H*W) - (h*W) - (H*w) + (h*w) << endl;
    return 0; 
}

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

signed main(){

  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  int m;
  cin>>m;
  vector<int> b(m);
  for(auto& bi:b)cin>>bi;

  cout<< (a<b) <<endl;

}


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

int main() {
    int N,M;
    cin>>N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin>>s.at(i);
    }
    cin>>M;
    vector<string> t(M);
    for(int i=0;i<M;i++){
        cin>>t.at(i);
    }
    
    vector<int> point(N);
    for(int i=0;i<N;i++){
        for(int k=0;k<N;k++){
            if(s.at(i)==s.at(k)){
                point.at(i)++;
            }
        }
        for(int k=0;k<M;k++){
            if(s.at(i)==t.at(k)){
                point.at(i)--;
            }
        }
    }

    int maxpoint=0;
    for(int i=0;i<N;i++){
        if(maxpoint<=point.at(i)){
            maxpoint=point.at(i);
        }
    }

    cout<<maxpoint<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<string> grid(H);
  for(int i=0;i<H;i++){
    cin>> grid[i];
  }
 vector<bool> a(H,false);
 vector<bool> b(W,false);
 for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(grid[i][j]=='#'){
        a[i]=true;
        b[j]=true;
         }
      }
    }
  
  
  for(int i=0;i<H;i++){
    if(a[i]){
      for(int j=0;j<W;j++){
        
          if(b[j]){
            cout<<grid[i][j];
        }
      }
      cout<<endl;
    }
      
    
  }
}





Measured memory_bytes: 3576
import java.util.*;
import java.math.*;
class Main {
    //
    static final long MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = 0;
        
        while(n > 0){
            n /= m;
            ans++;
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main()
{
  int x, y;
  cin >> x >> y;
  int INF = INT32_MAX;
  int ans1 = x <= y ? y - x : INF;
  int ans2 = -1 * x <= y ? y + x + 1 : INF;
  int ans3 = x <= -1 * y ? -1 * y - x + 1 : INF;
  int ans4 = -1 * x <= -1 * y ? -1 * y + x + 2 : INF;
  cout << min(min(ans1, ans2), min(ans3, ans4)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin >> A >> B;
    if (A*B==2)
    cout << "3";
    else if (A*B==3)
        cout << "2";
    else
        cout << "1";
}

// https://atcoder.jp/contests/abc148/tasks/abc148_a

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
//using namespace atcoder;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    int k;
    cin >> k;
    string ans = "";
    rep(i, k){
        ans += "ACL";
    }
    cout << ans << endl;
}



Measured memory_bytes: 3564
n = int(input())
a = [0]
for _ in range(n):
  a.append(int(input()))
visited = [False]*(n+1)
visited[1] = True
cnt = 0
but = 1
while True:
  nextb = a[but]
  if visited[nextb]:
    cnt = -1
    break
  elif nextb == 2:
    cnt += 1
    break
  else:
    but = nextb
    cnt += 1
    visited[but] = True
print(cnt)
    

Measured memory_bytes: 7884
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string n;
    cin >> n;
    
    int sum = 0;
    for (auto s: n){
        sum += int(s-'0');
    }
    
    printf("%s\n", (sum % 9 == 0) ? "Yes" : "No");
}


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T> Vec(int n, T v)
{
    return vector<T>(n, v);
}
template <class... Args>
auto Vec(int n, Args... args)
{
    auto val = Vec(args...);
    return vector<decltype(val)>(n, move(val));
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> par(N);
    vector<vector<int>> comp(N);
    for (int i = 0; i < N; i++) {
        par[i] = i;
        comp[i] = {i};
    }
    vector<int> size(N, 1);
    vector<ll> offset(N, 0);
    bool ans = true;
    for (int i = 0; i < M; i++) {
        int L, R, D;
        cin >> L >> R >> D;
        L--, R--;
        if (par[L] == par[R]) {
            if (offset[R] - offset[L] == D) {
                ;
            } else {
                ans = false;
            }
        } else {
            const int l = par[L];
            const int r = par[R];
            if (size[l] > size[r]) {
                const int d = offset[L] + D - offset[R];
                for (const int c : comp[r]) {
                    offset[c] += d;
                    par[c] = l;
                    comp[l].push_back(c);
                }
                size[l] += size[r];
                comp[r].clear();
            } else {
                const int d = offset[R] - D - offset[L];
                for (const int c : comp[l]) {
                    offset[c] += d;
                    par[c] = r;
                    comp[r].push_back(c);
                }
                size[r] += size[l];
                comp[l].clear();
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 11132
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_C
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int h = Integer.valueOf(inputs[0]);
                int w = Integer.valueOf(inputs[1]);
                
                if (h == 0 && w == 0) {
                    break;
                    // nothing to do.
                }
                
                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {
                        if ( ( j-i ) %2 != 0) {
                            System.out.print(DOTMARK);
                        } else {
                            System.out.print(HASHMARK);
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 32044
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll a[100000], b[100000];
vector<ll> v;

ll dif = 10800;
ll day = 86400;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    ll cur = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        v.push_back(cur+a[i]);
        cur += (a[i]+b[i]);
    }
    for(int i = 0; i < N; i++){
        v[i] %= day;
        v.push_back(v[i]+day);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < N; i++){
        auto p = upper_bound(v.begin(), v.end(), v[i]+dif);
        ans = max(ans, (int)(p-v.begin()-i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6888
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

ll fac[MAX],finv[MAX],inv[MAX];
//http://drken1215.hatenablog.com/entry/2018/06/08/210000
//テーブルを作る前処理　O(n)
//pが素数でなくてはならない
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
//二項係数計算
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


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

    int N,K;
    cin>>N>>K;
    vector<ll> V(N);
    for(int i=0;i<N;i++) cin>>V[i];
    sort(V.rbegin(),V.rend());
    COMinit();
    ll ans=0;
    for(int i=0;i<N;i++){
        int k=N-1-i;
        int r=K-1;
        ans+=COM(k,r)*V[i];
        ans%=MOD;
        if(k==r) break;
    }
    sort(V.begin(),V.end());
    for(int i=0;i<N;i++){
        int k=N-1-i;
        int r=K-1;
        ans-=(COM(k,r)*V[i])%MOD;
        ans+=MOD;
        ans%=MOD;
        if(k==r) break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  string A,B,C;
  cin >> A;
  cin >> B;
  cin >> C;
  int sum = 0;
  for(int i=0;i<N;++i) {
    int num[26] = {0};
    num[A[i]-'a']++;
    num[B[i]-'a']++;
    num[C[i]-'a']++;
    int n_max = 0;
    for(int j=0;j<26;++j) {
      if(num[j] > n_max) n_max = num[j];
    }
    sum += 3 - n_max;
  }
  cout << sum << endl;
  return 0;
}


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

int X[11][11];
int B[400];

int main() {
  int N, D, result;
  int i, j, n, d, l, b;
  scanf ("%d %d", &N, &D);
  
  for (n=0;n<N;n++) {
      for (d=0; d<D; d++) {
          scanf("%d", &X[n][d]);
      }
  }
  
  for (b=0;b<400;b++) {
      B[b] = b*b;
  }
  
  result = 0;
  for (i=0; i<N; i++) {
      for (j=i+1; j<N; j++) {
          l=0;
          for (d=0;d<D;d++) {
              l+=(X[i][d]-X[j][d])*(X[i][d]-X[j][d]);
          }
          for (b=0;b<400;b++) {
              if (B[b]==l) result++;
          }
      }
  }
  
  
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1200
#define ALPH_NUM 26

int main(void)
{
    char str[MAX];
    int alphabet[ALPH_NUM] = {0};
    int i;

    while (scanf("%s", str) != EOF) {
        i = 0;
        while (str[i] != '\0') {
            if (str[i] >= 'a' && str[i] <= 'z') {
                alphabet[str[i] - 'a']++;
            } else if (str[i] >= 'A' && str[i] <= 'Z') {
                alphabet[str[i] - 'A']++;
            }
            i++;
        }
    }
    
    for (i=0; i<ALPH_NUM; i++) {
        printf("%c : %d\n", 'a' + i, alphabet[i]);
    }

    return 0;
}


Measured memory_bytes: 2100
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;

  vector<ll>  h(n+1,0);

  rep(i,n) cin >> h[i];

  ll ans = 0;

  rep(i,n)
  {
    if(h[i+1] < h[i])
    {
      ans += h[i] - h[i+1];
    }
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
S = gets.chomp

mr = '01' .. '12'
f1, f2 = mr.member?(S[0, 2]), mr.member?(S[2, 2])
puts case
     when f1 && f2; "AMBIGUOUS"
     when f1; "MMYY"
     when f2; "YYMM"
     else ; "NA"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    set<pair<ll,ll>> S;
    rep(i,N) {
        ll x, l; cin >> x >> l;
        S.insert(make_pair(x + l, x - l));
    }

    auto x = S.begin();
    while (1) {
        auto y = next(x);
        if (y == S.end()) break;
        if (x->first <= y->second) {
            x = y;
            continue;
        } else {
            S.erase(y);
        }
    }
    cout << S.size() << endl;
}


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

int main(){

  long long n, a, cnt[1000000]={}, m=0;;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cnt[a-1]++;
    cnt[a]++;
    cnt[a+1]++;
  }

  for(int i=0;i<=100000;i++) m=max(m, cnt[i]);

  cout<<m<<endl;

  return 0;
}


Measured memory_bytes: 8064
h,w,k=list(map(int,input().split()))
c=[]
for i in range(h):
  c.append(list(input()))
  
bit_gyou=[]
for i in range(2**h):
    b_gyou=[]
    for j in range(h):
        if (i>>j & 1):
            b_gyou.append(1)
        else:
            b_gyou.append(0)
    bit_gyou.append(b_gyou)

    
bit_retu=[]
for i in range(2**w):
    b_retu=[]
    for j in range(w):
        if (i>>j & 1):
            b_retu.append(1)
        else:
            b_retu.append(0)
    bit_retu.append(b_retu)
ans=0
for i in bit_gyou:
  for j in bit_retu:
    cnt=0
    for gyou in range(len(i)):
      for retu in range(len(j)):
        if i[gyou]==1 and j[retu]==1 and c[gyou][retu]=="#":
          cnt=cnt+1
    if cnt==k:
      ans=ans+1
print(ans)

    



Measured memory_bytes: 9248
#include <algorithm>
#include <cstdio>
typedef long long LL;
inline int f(int n, int b, int k) {
  return (n / b) * (b - k) + std::max(n % b - k + 1, 0);
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  LL ans = 0;
  for (int b = k + 1; b <= n; ++b) ans += f(n, b, k);
  if (!k) ans -= n;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
fn main() {
	proconio::input!(n: usize, a: [i64; n], b: [i64; n]);
	let a_sum = a.iter().fold(0, |s, &x| s + x );
	let b_sum = b.iter().fold(0, |s, &x| s + x );
	if a_sum < b_sum {
		println!("-1");
		return;
	}

	let mut count = 0;
	let mut shortage = 0;
	let mut overage = Vec::new();
	for (i, &x) in a.iter().enumerate() {
		if x > b[i] {
			overage.push(x - b[i]);
		} else if x < b[i] {
			shortage += b[i] - x;
			count += 1;
		}
	}
	overage.sort();
	while shortage > 0 {
		shortage -= overage.pop().unwrap();
		count += 1;
	}

	println!("{}", count);
}

Measured memory_bytes: 6148
#include <iostream>
using namespace std;int M[105][100005];int A[105];int main(){ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);int n,k;cin>>n>>k;for(int i=0;i<n;i++)cin>>A[i];for(int i=0;i<=A[0];i++)M[0][i]=i+1;for(int i=A[0]+1;i<=k;i++)M[0][i]=M[0][A[0]];for(int i=1;i<n;i++){M[i][0]=1;for(int j=1;j<=k;j++){M[i][j]=M[i][j-1];M[i][j]+=(M[i-1][j]-(j-A[i]-1>=0?M[i-1][j-A[i]-1]:0))%1000000007;M[i][j]%=1000000007;}}cout<<(M[n-1][k]-M[n-1][k-1]+1000000007)%1000000007;return 0;}

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

using namespace std;

int main()
{
	int n;
	int a,b;
	scanf("%d %d %d",&n,&a,&b);	
	int ans;
	ans = a*n;
	if(ans>b)
	{
		printf("%d",b);
		return 0;
	}
	else
	{
		printf("%d",ans);
		return 0;
	}
	return 0;
} 

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

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  REP(i, 0, N) cin >> H[i];

  const ll INF = 1LL << 60;
  vector<ll> dp(N, INF);
  dp[0] = 0;

  REP(i, 0, N) {
    REP(k, 1, K + 1) {
      if (i + k < N) {
        dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]));
      }
    }
  }

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

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll N, K;
constexpr ll MOD = 1e9 + 7;
vector<vector<ll>> edge;

ll solve(ll curr, ll color_num, ll bro_num, ll depth, ll pre) {
    if (color_num <= 0) {
        return 0;
    }
    ll result = color_num - bro_num;
    ll next_bro_num = 0;
    (depth < 2 ? color_num-- : 0);

    for (ll next : edge[curr]) {
        if (next == pre) {
            continue;
        }
        (result *= solve(next, color_num, next_bro_num++, depth + 1, curr)) %= MOD;
    }

    return result;
}

int main() {
    cin >> N >> K;
    edge.resize(N);
    for (ll i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    cout << solve(0, K, 0, 0, -1) << endl;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define ll long long
#define lld long long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;

int f(int *a, int n) {
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	return dp[n - 1];
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	cout << f(a, n);
	return 0;
}

Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end

s=get_nsp
puts Array.new(s.size){"x"}.join()

Measured memory_bytes: 1788
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
// 5 9 13
int dx[13] = {0,1,0,-1,0,1,1,-1,-1,2,0,-2,0};
int dy[13] = {0,0,1,0,-1,1,-1,1,-1,0,2,0,-2};

bool inside(int x, int y) {
  return x >= 0 && x < 10 && y >= 0 && y < 10;
}

int main() {
  // ifstream cin("../test.txt");
  int p[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      p[i][j] = 0;
    }
  }
  int x,y,size;
  char g,h;
  while (cin >> x >> g >> y >> h >> size) {
    int m = size * 4 + 1;
    for (int i = 0; i < m; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (inside(nx, ny))
        p[nx][ny]++;
    }
  }

  int cnt = 0;
  int deepest = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (!p[i][j]) cnt++;
      deepest = max(deepest, p[i][j]);
    }
  }

  cout << cnt << endl << deepest << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for (auto &x: a) cin >> x;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (i%2 == 0 && a[i]%2 == 1) ++cnt;
	}
	cout << cnt << "\n";
}


Measured memory_bytes: 3604
def examA():
    N = I()
    L = LI()
    L.sort()
    if sum(L)<=L[-1]*2:
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, M = LI()
    A = [LI()for _ in range(N)]
    A.sort(key=lambda x:x[0])
    ans = 0
    for a,b in A:
        if M<=b:
            ans += a*M
            break
        ans += a*b
        M -= b
    print(ans)
    return

def examC():
    N = I()
    S = [SI()for _ in range(N)]
    D = defaultdict(int)
    for s in S:
        cur = []
        for i,j in Counter(s).items():
            cur.append((i,j))
        #print(cur)
        cur.sort()
        cur = tuple(cur)
        D[cur] += 1
    ans = 0
    for d in D.values():
        ans += (d-1)*d//2
    print(ans)
    return

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

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

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

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

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

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

Measured memory_bytes: 82400