akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(Pattern.compile("\\n"));

		while (true) {
			//Pattern p = p.compile("\n");
			String s = sc.next();
			boolean f = true;
			Stack<String> st = new Stack<String>();
			if (s.charAt(0) == '.') {
				break;
			}
			
			for (int i = 0; i < s.length(); i++) {
				char c[] = new char[1];
				c[0] = s.charAt(i);
				String s2 = new String(c);
				if (s2.equals("(") || s2.equals("[")) {
					st.push(s2);
				} else if (s2.equals(")")) {
					try {
						String s3 = st.pop();
						if (!s3.equals("(")) {
							f = false;
						}
					} catch(EmptyStackException e) {
						f = false;
						break;
					}
				} else if (s2.equals("]")) {
					try {
						String s3 = st.pop();
						if (!s3.equals("[")) {
							f = false;
						}
					} catch(EmptyStackException e) {
						f = false;
						break;
					}
				}
			}
			if (st.empty() == false) {
				f = false;
			}
			if (f) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
typedef std::map<int,int> mi;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
int A[100010];
mi m;
void solve(){
  rep(i,N){
    m[A[i]]++;
  }
  int even=0,odd=0;
  for(auto itr=m.begin();itr!=m.end();itr++){
    if(itr->second%2==1) odd++;
    else even++;
  }
  int res=even+odd;
  if(even%2==1) res--;
  prin(res);
    
}
int main(){
  cin>>N;
  rep(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int mod = 1000000007;
long long f(int a){
  if(a==1)return 1;
  return a*f(a-1)%mod;
}
int main(){
  int n,m;
  cin >> n >> m;
  if(n==m)cout << 2*f(n)%mod*f(m)%mod << endl;
  else if(abs(n-m)==1)cout << f(n)%mod*f(m)%mod << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 1792
N = int(input())
dp = [[0, 0, 0] for i in range(N+1)]
for i in range(1, N+1):
    a, b, c = list(map(int, input().split(' ')))
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
print(max(dp[-1]))

Measured memory_bytes: 22772
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int,int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 1e7 + 9;

int fact[mxN];

ll mult( int a, int b ){
    return ((ll) ((ll)a) * ((ll)b)    );
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    for(int i=1; i <= n; i++){
        for(int j=i; j <= n; j+=i){
            fact[j] += 1;
        }
    }
    ll ans = 0;
    for(int i=1; i <= n; i++) ans += mult( i, fact[i] );
    cout << ans;

}


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

const int maxn = 310, P = 998244353;
int n, m;
bitset<maxn> a[maxn];
vector<bitset<maxn> > base;

int qp(int x, int y) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        for (int j = m - 1, t; ~j; j--) {
            scanf("%d", &t);
            if (t) a[i].set(j);
        }
    }
    for (int i = 0; i < n; i++) {
        for (auto b : base) {
            auto c = b ^ a[i];
            for (int j = m - 1; ~j; j--) {
                if (c[j] < a[i][j]) { a[i] = c; break; }
                else if (c[j] > a[i][j]) break;
            }
        }
        if (a[i].any()) base.push_back(a[i]);
    }
    printf("%d\n", (qp(2, n + m - 1) - qp(2, n + m - 1 - base.size()) + P) % P);
    return 0;
}

Measured memory_bytes: 256
n,l = map(int,input().split())

li = [l+i for i in range(n)]

sum1 = sum(li)
ans = 0
abs1 = 10 ** 10

for i in li:
    sum2 = sum1 - i
    if abs(sum2-sum1) < abs1:
        abs1 = abs(sum2-sum1)
        ans = sum2

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

vi ABC;
signed main()
{
    ABC.resize(3);
    REP(i, 3)
    cin >> ABC[i];

    sort(ALL(ABC));
    cout << ABC[0] * ABC[1] / 2 << endl;
    // system("pause");
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Collection;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int W = in.nextInt();
            List<Pair> list = new ArrayList<>();
            for (int i = 0; i < N; i++)
            {
                int w = in.nextInt();
                int v = in.nextInt();
                int c = list.size();
                for (int j = 0; j < c; j++)
                {
                    int w_j = list.get(j).w;
                    int v_j = list.get(j).v;
                    if (w + w_j <= W)
                        list.add(new Pair(w + w_j, v_j + v));
                }
                list.add(new Pair(w, v));
                list.sort(Comparator.comparingInt(o -> o.v));

                int w_next = list.get(list.size() - 1).w;
                int v_next = list.get(list.size() - 1).v;
                for (int j = list.size() - 2; j >= 0; j--)
                {
                    int w_previous = list.get(j).w;
                    int v_previous = list.get(j).v;

                    if (w_previous > w_next) list.get(j).w = -1;
                    if (w_previous == w_next && v_previous <= v_next) list.get(j).w = -1;
                    if (w_next > w_previous && v_previous == v_next) list.get(j + 1).w = -1;

                    w_next = w_previous;
                    v_next = v_previous;
                }
                list.removeIf(pair -> pair.w == -1);
            }
            out.print(list.get(list.size() - 1).v);

        }

    }

    static class Pair
    {
        int w;
        int v;

        Pair(int w, int v)
        {
            this.w = w;
            this.v = v;
        }

    }
}



Measured memory_bytes: 47476
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) cnt++;
    }

    int ans = N - 1 - max(0, cnt - 2 * K);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  map<char,char> m,n;
  cin>>s>>t;
  for(int i=0;i<s.length();i++){
    if(!m[t[i]])m[t[i]]=s[i];
    else if(m[t[i]]!=s[i]){cout<<"No";return 0;}
  }
  for(int i=0;i<s.length();i++){
    if(!n[s[i]])n[s[i]]=t[i];
    else if(n[s[i]]!=t[i]){cout<<"No";return 0;}
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
lint ans = 0LL;
vl a, b, c;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> X >> Y >> A >> B >> C;

    a.resize(A);
    b.resize(B);
    c.resize(C);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, C) cin >> c[i];
    sort(allr(a));
    sort(allr(b));
    sort(allr(c));

    rep(i, X) ans += a[i];
    rep(i, Y) ans += b[i];

    int ai = X - 1;
    int bi = Y - 1;
    int ci = 0;

    while (true) {
        if (ci >= C) break;
    
        int ac = a[ai];
        int bc = b[bi];
        if (ai < 0) ac = INT32_MAX;
        if (bi < 0) bc = INT32_MAX;

        if (c[ci] < min(ac, bc)) break;


        if (ac <= bc && ai >= 0) {
            ans -= ac;
            ans += c[ci];
            ai--;
            ci++;
        } else if (bc <= ac && bi >= 0) {
            ans -= bc;
            ans += c[ci];
            bi--;
            ci++;
        } else if (ai >= 0) {
            ans -= a[ai];
            ans += c[ci];
            ai--;
            ci++;
        } else if (bi >= 0) {
            ans -= b[bi];
            ans += c[ci];
            bi--;
            ci++;
        } else {
            break;
        }
    }

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

Measured memory_bytes: 1408
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define memo(dp, val) memset(dp, val, sizeof(dp))
#define NINJA                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define all(a) a.begin(), a.end()
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define dloop(i, n) for (int i = n - 1; i >= 0; i--)
#define iii tuple<int, int, int>
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 1e6 + 10;
int fact[mxn];

int power(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  NINJA;

  fact[0] = 1;
  for1(i, mxn) fact[i] = (i * fact[i - 1]) % mod;

  //   debug() << deb(fact[5]);

  int n;
  cin >> n;

  cout << (((power(10, n) % mod - (2 * power(9, n) % mod) % mod + mod) % mod +
            power(8, n)) %
           mod) %
              mod
       << endl;

  return 0;
}

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

int main() {
  string C1, C2;
  cin >> C1 >> C2;
  bool flag = true;
  for(int i = 0; i < 3; i++)
    if(C1.at(i) != C2.at(2 - i))
      flag = false;
  if(flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
import collections

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

counter = collections.defaultdict(int)
for _ in range(m):
    b, c = map(int, input().split()) 
    counter[c] += b

alist.sort()
numbers = list(sorted(counter.keys()))

ans = 0
for a in alist:
    if len(numbers) > 0 and counter[numbers[-1]] == 0:
        numbers.pop()
        
    if len(numbers) > 0 and a < numbers[-1]:
         ans += numbers[-1]
         counter[numbers[-1]] -= 1
    else:
        ans += a

print(ans)

Measured memory_bytes: 23584
'''input
2 2
1 2
3 4
3 4
2 1
'''
# A coding delight
from sys import stdin, stdout
import gc
from copy import deepcopy
gc.disable()
input = stdin.readline

	
# main starts
n = int(input().strip())
string = input().strip()
count = 0
for i in range(n):
	if string[i] == 'A':
		if i + 1 < n and string[i + 1] == 'B':
			if i + 2 < n and string[i + 2] == 'C':
				count += 1

print(count)

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
int main(){
   double a,b,h,m;
   cin>>a>>b>>h>>m;
   double ans=a*a+b*b-2*a*b*cos(2*M_PI*((h+m/60)/12-m/60));
   printf("%.12lf\n",sqrt(ans));
   return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, x[100],y[100];
map<pll, ll> san;

ll i, j, k;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld%lld", &x[i], &y[i]);
    }
    fornum(i,0,N){
        fornum(j,0,N){
            if(i==j)
                continue;
            san[{x[i] - x[j], y[i] - y[j]}]++;
        }
    }
    ll anss = 0;
    for (auto it = san.begin(); it != san.end();++it){
        if(anss<it->second){
            anss = it->second;
        }
    }
    printf("%lld", N - anss);

    return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (null, elem)
import Control.Monad
import Data.Char
import Data.List hiding (insert, null, elem)
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n, m] <- getIntList
  queue <- fromList <$> getIntList
  print $ solve m queue

solve :: Int -> Heap Int -> Int
solve m queue
  | m == 0 = sum . toList $ queue
  | otherwise = solve (m - 1) . uncurry insert . mapFst (`div`2) . deleteFindMax $ queue

mapFst :: (a -> b) -> (a, c) -> (b, c)
mapFst f (a, b) = (f a, b)

-- Leftist Heap
data Heap a =
  Empty |
  Heap {
    rank :: Int,
    elem :: a,
    left :: Heap a,
    right ::Heap a}

empty :: Heap a
empty = Empty

null :: Heap a -> Bool
null Empty = True
null (Heap _ _ _ _) = False 

singleton :: a -> Heap a
singleton x = Heap 1 x Empty Empty

merge :: Ord a => Heap a -> Heap a -> Heap a
merge h     Empty = h
merge Empty h     = h
merge h1 h2
  | elem h1 > elem h2 = makeHeap (elem h1) (left h1) (merge (right h1) h2)
  | otherwise = makeHeap (elem h2) (left h2) (merge (right h2) h1)

makeHeap :: a -> Heap a -> Heap a -> Heap a
makeHeap x a b =
  if ra >= rb then Heap (rb + 1) x a b else Heap (ra + 1) x b a
  where 
    rb = if null b then 0 else rank b
    ra = if null a then 0 else rank a

insert :: Ord a => a -> Heap a -> Heap a
insert x h = merge (singleton x) h

deleteFindMax :: Ord a => Heap a -> (a, Heap a)
deleteFindMax Empty = error "Empty Heap"
deleteFindMax (Heap _ x a b) = (x, merge a b)

fromList :: Ord a => [a] -> Heap a
fromList = foldl (flip insert) Empty

toList :: Ord a => Heap a -> [a]
toList h
  | null h = []
  | otherwise = let (x, h') = deleteFindMax h
                in x : toList h'
-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

Measured memory_bytes: 17788
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def add_mod(a,b): return (a+b) % MOD

N,W = imn()
wv = [iln() for _ in range(N)]
max_v = 10**3*100+1
dp =[[10**10 for _ in range(max_v)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for sum_v in range(max_v):
        if sum_v - wv[i][1] >= 0: 
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v-wv[i][1]]+wv[i][0])
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
ans = 0
for i in range(max_v):
    if dp[N][i] <= W: ans = i
print(ans)

Measured memory_bytes: 181820
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n;
	cin >> n;
	vector<int> b(n - 1);
	rep(i, n - 1) cin >> b[i];

	int ans = 0;
	ans += b[0];
	ans += b[n - 2];

	rep(i, n - 2) {
		ans += min(b[i], b[i + 1]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
x = int(input())
MAX = 10 ** 6
sieve = [True] * MAX
sieve[0] = False
sieve[1] = False
for i in range(2, MAX):
  if sieve[i] == False:
    continue
  for j in range(i*2, MAX, i):
    sieve[j] = False
#print(sieve[:30])
for j in range(x, MAX):
  if sieve[j]:
    print(j)
    exit(0)
  

Measured memory_bytes: 79676
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    word = list()
    pre_word = input()
    word.append(pre_word)

    for i in range(n - 1):
        w = input()

        if w not in word:
            word.append(w)

            if pre_word[-1] != w[0]:
                print('No')
                exit()
        else:
            print('No')
            exit()

        pre_word = w

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string in; cin >> in;
  stringstream ss(in);
  for (int i = 0; i < 2; i++) {
    string s;
    getline(ss, s, '/');
    int t = stoi(s);
    if (i == 0 && t < 2019) {
      cout << "Heisei" << '\n';
      return;
    }
    if (i == 0 && t > 2019) {
      cout << "TBD" << '\n';
      return;
    }
    if (i == 1 && t <= 4) {
      cout << "Heisei" << '\n';
      return;
    }
    if (i == 1 && t > 4) {
      cout << "TBD" << '\n';
      return;
    }
  }
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int hand,rock[6],sci[6],par[6],cou_r,cou_s,cou_p;

void priming(int x,int i){
  if(x==1){
    rock[i]=1;
    cou_r++;
  }else if(x==2){
    sci[i]=1;
    cou_s++;
  }else if(x==3){
    par[i]=1;
    cou_p++;
  }
}

int main(){
  
  while(1){
    for(int i=0;i<6;i++)rock[i]=sci[i]=par[i]=0;
    cou_r=cou_s=cou_p=0;
    cin>>hand;
    
    if(hand==0)break;
    
    priming(hand,0);
    
    for(int i=1;i<5;i++) {
      cin>>hand;
      priming(hand,i);
    }
    
    if((cou_r!=0&&cou_s!=0&&cou_p!=0)||cou_r==5||cou_s==5||cou_p==5){
      for(int i=0;i<5;i++)cout<<"3"<<endl;
    }else if(cou_p==0){
      for(int i=0;i<5;i++){
	if(rock[i]==1)cout<<"1"<<endl;
	else cout<<"2"<<endl;
      }
    }else if(cou_r==0){
      for(int i=0;i<5;i++){    
	if(sci[i]==1)cout<<"1"<<endl;
	else cout<<"2"<<endl;
      }
    }else if(cou_s==0){
      for(int i=0;i<5;i++){
        if(par[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
      }
    }
  
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>//author::@whohet-->Het Patel
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define uint unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238

using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;int t=0;
	while(a>0 && c>0)
	{
		if(t%2==0)
			c=c-b;
		else
			a=a-d;
		t++;

	}
	if(a<=0)
		cout<<"No";
	else
		cout<<"Yes";

}



Measured memory_bytes: 3624
class Node:
    def __init__(self):
        self.key = -1
        self.p = -1
        self.l = -1
        self.r = -1

def insert(k):
    y = -1
    x = root[0]
    z = len(T)
    T.append(Node())
    T[z].key = k
    while x != -1:
        y = x
        if T[z].key < T[x].key: x = T[x].l
        else: x = T[x].r
    T[z].p = y
    if y == -1: root[0] = z
    elif T[z].key < T[y].key: T[y].l = z
    else: T[y].r = z

def find(k):
    x = root[0]
    while x != -1 and T[x].key != k:
        if k < T[x].key: x = T[x].l
        else: x = T[x].r
    return x

def inorder(u):
    if u == -1: return
    inorder(T[u].l)
    print(" {}".format(T[u].key),end="")
    inorder(T[u].r)

def preorder(u):
    if u == -1: return
    print(" {}".format(T[u].key),end="")
    preorder(T[u].l)
    preorder(T[u].r)



m = int(input())
T = []
root = [-1]
lst = [input().split() for _ in range(m)]
for i in range(m):
    comm = lst[i][0]
    if len(lst[i]) == 2: key = int(lst[i][1])
    if comm == "insert":
        insert(key)
    elif comm == "find":
        print("yes" if find(key) != -1 else "no")
    else:
        inorder(root[0])
        print("")
        preorder(root[0])
        print("")


Measured memory_bytes: 241884
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int n = data[0];
        int[][][] House = new int[4][3][10];
        int i, j, k;
        for(i = 0; i < 4; i++){
            for(j = 0; j < 3; j++){
                for(k = 0; k < 10; k++) House[i][j][k] = 0;
            }
        }
        for(i = 0; i < n; i++){
            data = makeIntArray(br);
            House[data[0] - 1][data[1] - 1][data[2] - 1] += data[3];
        }
        for(i = 0; i < 4; i++){
            for(j = 0; j < 3; j++){
                for(k = 0; k < 10; k++){ System.out.print(" " + House[i][j][k]); }
                System.out.println();
            }
            if(i < 3){
                for(k = 0; k < 20; k++){ System.out.print('#'); }
                System.out.println();
            }
        }
    }
    public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    }
}


Measured memory_bytes: 24804
#include <stdio.h>

void print_array(int a[], int length)
{
    for(int i=0; i<length; i++){
        if(i==length-1)
            printf("%d\n", a[i]);
        else
            printf("%d ", a[i]);
    }
}

void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int insertion_sort(int a[], int length)
{
    int swap_num = 0;
    for(int i=0; i<length; i++){
        int min_i = i;
        int swap_flag = 0;
        for(int j=i; j<length; j++){
            if(a[j] < a[min_i]){
                min_i = j;
                swap_flag = 1;
            }
        }
        swap(&a[i], &a[min_i]);
        if(swap_flag == 1) swap_num++;
    }
    return swap_num;
}

int main(){
    int data_length, arr[110];
    scanf("%d", &data_length);
    for(int i=0; i<data_length; i++){
        scanf("%d", &arr[i]);
    }
    int swap = insertion_sort(arr, data_length);
    print_array(arr, data_length);
    printf("%d\n", swap);
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
vll d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll memo, ans = 0;
  for (ll i = 0; i < n; i++) {
    memo = a[i];
    ll cnt = 0;
    while (memo == a[i]) {
      cnt++;
      i++;
    }
    i--;
    if (cnt % 2 > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self//value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())

class Combination:
    def __init__(self,max_n):
        self.max_n=0
        self.fact=[Fp(1)]
        self.ifact=[Fp(1)]
        self.make_fact_list(max_n)
    def C(self,n,k):return self.fact[n]*self.ifact[k]*self.ifact[n-k] if 0<=k<=n else 0
    def H(self,n,k):return self.C(n+k-1,k) if n or k else 1
    def P(self,n,k):return self.fact[n]*self.ifact[n-k] if 0<=k<=n else 0
    def make_fact_list(self,max_n):
        if max_n<=self.max_n: return
        self.fact+=[Fp(0)]*(max_n-self.max_n)
        self.ifact+=[Fp(0)]*(max_n-self.max_n)
        for i in range(self.max_n+1,max_n+1):
            self.fact[i]=self.fact[i-1]*i
            self.ifact[i]=self.ifact[i-1]//i
        self.max_n=max_n

N, M = sorted(map(int, input().split()))
p = Combination(M)
ans = p.fact[N]*p.fact[M]
if N == M:
    ans *= 2
if abs(N-M) > 1:
    ans = 0
print(ans)

Measured memory_bytes: 19272
import core.stdc.stdio;
import std.algorithm;
import std.range;
import std.typecons;
import std.stdio;

struct Seg{
	int[] crd;
	int s=1;
	long[] v,d;
	void Init(){
		crd.sort;
		int last=-1,i;
		foreach(c;crd){
			if(last!=c) crd[i++]=c;
			last=c;
		}
		while(s<i)s*=2;
		crd.length=s+1;
		foreach(ref v;crd[i..$]) v=last;
		v=new long[s*2],d=new long[s*2];
	}
	void Propagate(int i,int l,int r){
		v[i]+=d[i]*(crd[r]-crd[l]);
		d[i*2]+=d[i],d[i*2+1]+=d[i];
		d[i]=0;
	}
	long _add(int b,int e,int l,int r,int a,int i){
		if(e<=l||r<=b)
			return v[i]+d[i]*(crd[r]-crd[l]);
		else if(b<=l&&r<=e){
			d[i]+=a;
			return v[i]+d[i]*(crd[r]-crd[l]);
		}else{
			Propagate(i,l,r);
			return v[i]=_add(b,e,l,(l+r)/2,a,i*2)+_add(b,e,(l+r)/2,r,a,i*2+1);
		}
	}
	void Add(int b,int e,int a){
		_add(cast(int)crd.assumeSorted.lowerBound(b).length,cast(int)crd.assumeSorted.lowerBound(e).length,0,s,a,1);
	}
	long _get(int b,int e,int l,int r,int i){
		if(e<=l||r<=b)
			return 0;
		else if(b<=l&&r<=e)
			return v[i]+d[i]*(crd[r]-crd[l]);
		else{
			Propagate(i,l,r);
			return _get(b,e,l,(l+r)/2,i*2)+_get(b,e,(l+r)/2,r,i*2+1);
		}
	}
	long Get(int b,int e){
		if(e<=crd[0]||crd[$-1]<=b) return 0;
		b=max(b,crd[0]),e=min(e,crd[$-1]);
		int u=cast(int)crd.assumeSorted.lowerBound(b).length;
		int v=cast(int)crd.assumeSorted.lowerBound(e).length;
		long ret = _get(u,v,0,s,1);
		if(crd[u]!=b)
			ret+=_get(u-1,u,0,s,1)/(crd[u]-crd[u-1])*(crd[u]-b);
		if(crd[v]!=e)
			ret-=_get(v-1,v,0,s,1)/(crd[v]-crd[v-1])*(crd[v]-e);
		return ret;
	}
}

void main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	alias Tuple!(int,"a",int,"b",int,"c") query;
	query[] aq = new query[m];
	int[int] idx;
	foreach(ref v;aq){
		scanf("%d%d%d",&v.a,&v.b,&v.c);
		idx[v.c]=1;
	}
	int[] vs=idx.keys.sort;
	foreach(int i,k;vs)
		idx[k]=i;
	Seg[] ss = new Seg[vs.length];
	foreach(v;aq){
		int i=idx[v.c];
		while(i<ss.length){
			ss[i].crd~=v.a;
			ss[i].crd~=v.b+1;
			i+=(i+1)&(-i-1);
		}
	}
	foreach(ref s;ss)
		s.Init;
	foreach(v;aq){
		int i=idx[v.c];
		while(i<ss.length){
			ss[i].Add(v.a,v.b+1,1);
			i+=(i+1)&(-i-1);
		}
	}
	int d;
	foreach(i;0..20)
		if((1<<i)&cast(int)(ss.length))
			d=(1<<i);
	foreach(_;0..q){
		int a,b;
		long c;
		scanf("%d%d%lld",&a,&b,&c);
		int i=d;
		int ans=cast(int)vs.length;
		while(1){
			if(i<=vs.length){
				long r=ss[i-1].Get(a,b+1);
				if(r>=c) ans=i;
				int bb=i&-i;
				if(bb==1) break;
				if(r<c) c-=r,i+=bb/2;
				else i-=bb/2;
			}else
				i-=(i&-i)/2;
		}
		printf("%d\n",vs[ans-1]);
	}
}

Measured memory_bytes: 121968
n = int(input());div=[];ans=[]
for i in range(1,int(n**0.5)+2):
  if n%i == 0:
    div.append(i);div.append(n//i)
    
for i in div:
  if i == 1:
    continue
  tmp = n
  while tmp % i == 0:
    tmp //= i
  if tmp % i ==1:
    ans.append(i)
    
n -= 1
for i in range(1,int(n**0.5)+2):
  if n%i == 0:
    ans.append(i);ans.append(n//i)
    
print(len(set(ans))-1)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
int main(){
  int a,b,m,t,result;
  vector<int> A,B,M;
  cin>>a>>b>>m;
  for(int i=0;i<a;i++){
    cin>>t;
    A.pb(t);
  }
  for(int i=0;i<b;i++){
    cin>>t;
    B.pb(t);
  }
  int x,y,c;
  for(int i=0;i<m;i++){
    cin>>x>>y>>c;
    M.pb(x);
    M.pb(y);
    M.pb(c);
  }
  int mina = *min_element(all(A));
  int minb = *min_element(all(B));
  result = mina+minb;
  int testresult;
  int count=0;
  int aa,bb,cc;
  for(int i=0;i<m;i++){
    aa = M.at(count);
    bb = M.at(count+1);
    cc = M.at(count+2);
    testresult = A.at(aa-1) + B.at(bb-1) - cc;
    result = min(result,testresult);
    count=count+3;
  }
  cout<<result;
}

Measured memory_bytes: 3316
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

long long M = 1000000007;

int n;
typedef vector<vector<long long>> Mat;

Mat mult(Mat x, Mat y){
    Mat z(n,vector<long long>(n,0));
    for(int i=0;i<n;++i){
        for(int k=0;k<n;++k){
            for(int l=0;l<n;++l){
                z[i][k] += x[i][l]*y[l][k];
                z[i][k] %= M;
            }
        }
    }
    return z;
}

int main(int argc, char const *argv[]) {
    cin>>n;
    long long kk;cin>>kk;
    Mat a(n,vector<long long>(n));
    Mat res(n,vector<long long>(n,0));
    for(int i=0;i<n;++i)for(int k=0;k<n;++k)cin>>a[i][k];
    for(int i=0;i<n;++i)res[i][i] = 1;
    while(kk>0){
        if(kk%2==1)res = mult(res,a);
        kk>>=1;
        a = mult(a,a);
    }
    long long ress = 0;
    for(int i=0;i<n;++i)for(int k=0;k<n;++k){
        ress += res[i][k];
        ress %= M;
    }
    cout<<ress<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    S = input()
    K = int(input())

    if S == 1:
        print(S[0])
        return

    if K == 1:
        print(S[0])
        return

    i = 0
    while True:
        if S[i] != "1":
            print(S[i])
            return

        if i == K - 1:
            print(1)
            return

        i += 1


main()


Measured memory_bytes: 5012
#include<stdio.h>
#include<string.h>
 
    int dice[6];
    int i,t;
     
void nmov(){
    int buf;
     buf = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[4];
    dice[4] = buf;
}
void emov(){
    int buf;
    buf = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[2];
    dice[2] = buf;
}
void wmov(){
    int buf;
    buf = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[3];
    dice[3] = buf;
}
void smov(){
int buf;
    buf = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[1];
    dice[1] = buf;
}
 
int main(){
    for(i=0;i<6;i++){
    scanf("%d",&dice[i]);
    }
    char c[105];
    scanf("%s",c);
    for(i=0; i<strlen(c); i++){
        if(c[i]=='N'){nmov();}
        else if(c[i]=='E'){emov();}
        else if(c[i]=='W'){wmov();}
        else if(c[i]=='S'){smov();}
    }
    printf("%d\n",dice[0]);
          
    return 0;
}


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

int money[4]={10,50,100,500};
int n[4];
int ans[4];
bool flag=false;

void change(int x){

  for(int i=3 ; i >=0 ; i--){
    ans[i]=x/money[i];
    x%=money[i];
  }
  
}
int main(){
  
  int c;

  while(1){
    
    cin >>c;
    if(c==0)break;
   
    if(flag == true)cout <<endl; 
    flag=true;

    int sum=0;

    for(int i=0 ; i < 4 ; i++){
      cin >>n[i];
      sum+=n[i]*money[i];
    }
    
    sum-=c;
    change(sum);

    for(int i=0 ; i < 4 ; i++){
      if(n[i]-ans[i] > 0){
	cout <<money[i]<<" "<<n[i]-ans[i]<<endl;
      }
    }

  }
  
  
  return 0;
}

Measured memory_bytes: 1160
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define num 100010
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)

using namespace std;

int main()
{
    int a;
    cin>>a;
    int x=0,m=1;
    forll(i,1,3,1)
    {
        m*=a;x+=m;
    }
    cout<<x<<"\n";
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[1<<26];
int val[214514];
int ans[214514];
signed main(){
	string str;
	cin>>str;
	int n = str.size();
	for(int i=1;i<=n;i++){
		int cur = str[i-1] - 'a';
		val[i] = val[i-1] ^ ( 1 << cur ) ;
	}
	for(int i=0; i < (1<<26) ; i++){
		dp[i] = inf;
	}
	dp[0] = 0;
	for(int i=1;i<=n;i++){
		vector<int> v;
		int cur = val[i];
		v.pb( dp[ cur ] );
		for(int j=0;j<26;j++){
			v.pb( dp[ cur ^ (1<<j) ] );
		}
		sort(v.begin(),v.end());
		ans[i] = v[0] + 1 ;
		//cout<<ans[i]<<endl;
		dp[ cur ] = min( dp[cur], ans[i] );
	}
	cout<<ans[n]<<endl;
	return 0;
}

Measured memory_bytes: 264324
#include<bits/stdc++.h>
using namespace std;
int64_t nx (int64_t n){
  return n*(n+1)/2;
}

int main(){
  int N;
  cin >> N;
  vector<string> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    sort(vec.at(i).begin(), vec.at(i).end());
  }

  int64_t ans = 0;
  map<string, int64_t> mp;
  for(int i=0; i<N; i++){
    string S = vec.at(i);
   if(mp.count(S)) {
   ans -= nx(mp.at(S));
   mp.at(S)++;
   ans += nx(mp.at(S));
   }
   else{
   mp[S] = 0;
   }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 18176
fn main() {
    let n:i32 = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().unwrap()
    };
    let mut a : Vec<i32> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
    };

    a.sort();
    let mi_lo = n / 2 - 1;
    let mi_hi = mi_lo + 1;

    println!("{}", a[mi_hi as usize] - a[mi_lo as usize]);
}


Measured memory_bytes: 4352
import std.stdio;
import std.algorithm;
import std.array;
import std.string;
import std.conv;

int[] data;

void solve(int n, int m) {
  if (n == 0) {
    for(uint i = 0; i < data.length; i++) write(format("%s%d", i ? " " : "", data[i]));
    writeln;
    return;
  }
  for(int i = min(n, m); i >= 1; i--) {
    data ~= i;
    solve(n - i, i);
    data.popBack;
  }
}

void main() {
  int n;
  while((n = readln.chomp.to!int) != 0) solve(n, n);
}

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

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;


int main()
{
	int N,X;
	cin>>N>>X;
	
	vector<int> m;
	int b=0;
	
	REP(i,N){
		int d;
		cin>>d;
		m.push_back(d);
		b=b+d;
	}
	
	b=X-b;
	int c;
	c=*min_element(m.begin(),m.end());
	b=b/c;
	
	cout<<N+b<<endl;
	
}
	
	
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int taka = (a+d-1)/d;
  int aoki = (c+b-1)/b;
  if(taka >= aoki) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main()
{
  int64_t n;

  cin >> n;

  vector<int64_t> a(n + 1);
  vector<int64_t> b(n);

  for(int64_t i = 0;
      i < n + 1;
      ++i)
    {
      cin >> a[i];
    }
  for(int64_t i = 0;
      i < n;
      ++i)
    {
      cin >> b[i];
    }

  int64_t ans = 0;
  for(int64_t i = 0;
      i < n;
      ++i)
    {
      if(a[i] <= b[i])
        {
          ans += a[i];
          b[i] -= a[i];
          if(a[i + 1]  <= b[i])
            {
              ans += a[i + 1];
              a[i + 1] = 0;
            }
          else
            {
              ans += b[i];
              a[i + 1] -= b[i];
            }
        }
      else
        {
          ans += b[i];
        }
    }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,g=0;
  cin>>N;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    g+=i;
  }
  if(g%10!=0){
    cout<<g<<endl;
    return 0;
  }
  sort(A.begin(),A.end());
  for(int i:A)
    if(i%10!=0){
      cout<<g-i<<endl;
      return 0;
    }
  cout<<0<<endl;
}

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

int a[4],b[4];
void search()
{
	int hit=0,blow=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(a[i] == b[j] && i==j)
				hit++;
			else if(a[i]==b[j])
				blow++;
		}
	}
	cout << hit << ' ' << blow << endl;
}

int main()
{
	while(cin >> a[0]){
		for(int i=1;i<4;i++){
			cin >> a[i];
		}
		for(int i=0;i<4;i++){
			cin >> b[i];
		}
		search();
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000



int main() {
	
	int N,K,C;
	cin>>N>>K>>C;
	
	string S;
	cin>>S;
	
	vector<int> dp(N+1,0);
	
	for(int i=0;i<N;i++){
		if(S[i]=='o'){
			int j = min(i+C+1,N);
			dp[j] = max(dp[j],dp[i]+1);
		}
		dp[i+1] = max(dp[i+1],dp[i]);
	}
	
	if(dp.back()>K){
		cout<<endl;
		return 0;
	}
	
	vector<int> ans;
	vector<bool> valid(N+1,false);
	valid[N] = true;
	for(int i=N-1;i>=0;i--){
		if(valid[i+1]&&dp[i+1]==dp[i]){
			valid[i]=true;
		}
		if(S[i]=='o'){
			int j = min(i+C+1,N);
			if(valid[j]&&dp[j]==dp[i]+1){
				valid[i] = true;
				ans.push_back(i);
			}
		}
	}
	
	sort(ans.begin(),ans.end());
	
	vector<int> ans2;
	
	for(int i=0;i<ans.size();i++){
		bool f1 = false,f2 = false;
		if(i==0||ans[i]-ans[i-1]>C){
			f1=true;
		}
		if(i==ans.size()-1||ans[i+1]-ans[i]>C){
			f2 = true;
		}
		if(f1&&f2)ans2.push_back(ans[i]);
	}
	
	for(int i=0;i<ans2.size();i++){
		cout<<ans2[i]+1<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 4220
#include <stdio.h>
signed main(){
    int N;
    int i;
    long long sum=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++){
        if(i%3!=0){
            if(i%5!=0){
              sum+=i;
            }
        }
    }
    printf("%lld\n",sum);
    return(0);
}

Measured memory_bytes: 1600
import sys

direction = {'N' : 0, 'E' : 1, 'S' : 2, 'W' : 3}
step = [( -1, 0 ), ( 0, 1 ), ( 1, 0 ), ( 0, -1 )]
vv = []

while True:
    W, H = map( int, sys.stdin.readline().rstrip().split() )
    if W == 0 and H == 0: break
    m = [ list( sys.stdin.readline().strip() ) for i in xrange( H ) ]
    people = [ [ i, j, direction[ m[i][j] ] ] for i in xrange( H ) for j in range( W )
               if m[i][j] in "NESW" ]
    time = 0
    while any( people ):
        time += 1
        if time > 180:
            time = -1
            break
        sched = []
        for n in xrange( len( people ) ):
            if people[n] is None: continue
            x, y, d = people[n]
            for i in range(1, -3, -1):
                    dx, dy = step[(d + i) % 4]
                    if 0 <= x+dx < H and 0 <= y+dy < W and m[x+dx][y+dy] in "X.":
                        people[n][2] = (d + i) % 4
                        beat = True
                        for k in range( len( sched ) ):
                            xx, yy, dd = sched[k][1:]
                            if ( x+dx, y+dy ) == ( xx, yy ):
                                if dd < (d + i) % 4:
                                    sched[k] = ( n, x+dx, y+dy, (d + i) % 4 )
                                    beat = False
                                    break
                                else:
                                    beat = False
                                    break
                        if beat:
                            sched.append( ( n, x+dx, y+dy, (d + i) % 4 ) )
			break
        for ( k, x, y, d ) in sched:
            m[ people[k][0] ][ people[k][1] ] = '.'
            if m[x][y] == 'X':
                people[k] = None
            else:
                m[x][y] = 'H'
                people[k] = list([x, y, d])
    if time >= 0:
        vv.append(time)
    else:
        vv.append('NA')

for v in vv:
    print v

Measured memory_bytes: 4384