akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int X = 100000;
        int N = cin.nextint;
        var A = new int[X];
        var B = new int[X];
        var IDA = new int[X];
        var IDB = new int[X];
        var V = cin.scanint;
        for (int i = 0; i < N; i++)
        {
            if (i % 2 == 0)
            {
                A[V[i] - 1]++;
            }
            else
            {
                B[V[i] - 1]++;
            }

        }
        for (int i = 0; i < X; i++)
        {
            IDA[i] = i;
            IDB[i] = i;
        }
        Array.Sort(A, IDA);
        Array.Sort(B, IDB);

        Array.Reverse(A);
        Array.Reverse(B);
        Array.Reverse(IDA);
        Array.Reverse(IDB);

       // WriteLine(A[0] + " " + IDA[0] + " " + A[1] + " " + IDA[1]);
        //WriteLine(B[0] + " " + IDB[0] + " " + B[1] + " " + IDB[1]);


        int M = N / 2;
        if (IDA[0] != IDB[0])
        {
            WriteLine(N - A[0] - B[0]);
        }
        else
        {
            if (N == 2)
            {
                WriteLine(1);
            }
            else
            {
                int max = Math.Max(A[0] + B[1], A[1] + B[0]);
                WriteLine(N - max);
            }
        }


    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 20576
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
-- end of templete





main = map readDouble . words <$> getLine >>= print . (/3.305785) . apply2 (*)

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

int main() {
  double N,K,P=0;
  cin >> N >> K;
  
  for(int i=1; i<=N; i++){
    int a=i;
    double S=1;
    while(a<K){
      S=S/2;
      a=a*2;
    }
    P+=S;
  }
  printf("%.16f", P/N); 
}

Measured memory_bytes: 256
n=int(input())
s=[]
x=0
for i in range(n):
  s.append(int(input()))
  x+=s[i]
s.sort()
if(x%10!=0):print(x)
else:
  for i in range(n):
    if(s[i]%10!=0):
      print(x-s[i])
      break
  else:print(0)

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

int main()
{
    int judge=0;
    int cnt = 0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int dice1,dice2;
        cin >> dice1 >> dice2;
        if(dice1==dice2){
            cnt += 1;
            if(cnt==3) judge = 1;
        }
        else cnt = 0;
    }
    if(judge==1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

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

    int m = 1000001;
    bool b[m];
    b[0] = b[1] = false;
    for (int i = 2; i < m; i++) {
        b[i] = true;
    }
    int total = 0;
    for (int i = 2; i < m; i++) {
        if (!b[i]) {
            continue;
        }
        for (int j = 2 * i; j < m; j += i) {
            b[j] = false;
        }
        int count = 0;
        while (n % i == 0) {
            count ++;
            n = n / i;
        }
        if (count > 0) {
            int x = (int(sqrt(8 * count + 1)) - 1) / 2;
            // cout << i << ": " << count << endl;
            total += x;
        }
        if (n == 1) {
            break;
        }
    }
    if (n > 1) {
        total += 1;
    }
    cout << total << endl;
}

Measured memory_bytes: 4160
#include <stdio.h>

int calc(int h, int val){
    return (h==0)*(-val)+(h!=0)*val;
}

int main()
{
    int a,b,c,d;
    int res,n;
    scanf("%d", &n);
    d = n % 10;
    c = (n/10)%10;
    b = (n/100)%10;
    a = n/1000;
    int i;
    for (i = 0; i < 8; i++){
        res = a+calc((i&4),b)+calc((i&2),c)+calc((i&1),d);
        if (res == 7)
            break;
    }
    printf("%d",a);

    if ((i&4)==0){
        printf("-");
    }else{
        printf("+");
    }
    printf("%d",b);

    if ((i&2)==0){
        printf("-");
    }else{
        printf("+");
    }
    printf("%d",c);

    if ((i&1)==0){
        printf("-");
    }else{
        printf("+");
    }
    printf("%d=7\n",d);
    return 0;
}


Measured memory_bytes: 128
// #define DEBUG_MODE
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

const int N = 200010;
char s[N];
int n;

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%s", s);
	n = strlen(s);
	vi a;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') a.push_back(0);
		else if (s[i] == 'C') a.push_back(-1);
		else {
			if (i < n - 1 && s[i + 1] == 'C') {
				a.push_back(1); i++;
			}
			else a.push_back(-1);
		}
	}
	// for (int i = 0; i < a.size(); i++) printf("[%d]", a[i]);
	reverse(begin(a), end(a));
	ll ans = 0, cnt = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == -1) cnt = 0;
		else if (a[i] == 1) cnt++;
		else ans += cnt;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1528
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
v_rev = v[::-1]
ans = -float("inf")

for a in range(min(n, k) + 1):
    b_list = [i for i in range(min(n, k) - a + 1)]
    for b in b_list:
        c = k - (a + b)
        left = v[:a]
        right = v_rev[:b]
        minus_list = []
        for i in left:
            if i < 0:
                minus_list.append(i)
        for j in right:
            if j < 0:
                minus_list.append(j)
        minus_list.sort()
        res = sum(left) + sum(right) - sum(minus_list[:c])
        # print(a, b, c, res)
        # print(left, right, minus_list)
        ans = max(ans, res)
print(ans)


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

#define PI acos(-1)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("maxflow.in", "r", stdin),freopen ("maxflow.out", "w", stdout);
#define all(v) ((v).begin()), ((v).end())

using namespace std;

typedef pair<int, int> pii;

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

const int N = 1e5 + 5;
const int LOG = 20;

int n, L, q;
int to[N][LOG], a[N];

void pre() {
  memset(to, -1, sizeof to);
  for(int i = 0; i < n - 1; i++) {
    int idx = lower_bound(a, a + n, a[i] + L) - a;
    if(idx == n || a[idx] > a[i] + L) {
        idx--;
    }
    assert(idx > i);
    to[i][0] = idx;
  }
  for(int i = 0; i < LOG; i++){
    to[n - 1][0] = n - 1;
  }
  for(int j = 1; j < LOG; j++) {
    for(int i = 0; i < n; i++) {
      if(to[i][j - 1] != -1) {
        to[i][j] = to[to[i][j - 1]][j - 1];
      }
    }
  }
}

int getKth(int u, int k) {
  //cout << "before " << u << "kth " << k << endl;
  for(int i = 0; k; i++) {
    if(k & 1) {
      u = to[u][i];
    }
    k >>= 1;
  }
  //cout << "u " << u << endl;
  return u;
}

int f(int from, int to) {
  int L = 0, R = n, ans = n;
  while(L <= R) {
    int mid = (L + R) / 2;
    if(getKth(from, mid) >= to) {
      ans = mid;
      R = mid - 1;
    }else {
      L = mid + 1;
    }
  }
  return ans;
}

int main() {
#ifndef ONLINE_JUDGE
  //freopen ("in.txt", "r", stdin);
#endif
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> L >> q;
  pre();
  while(q--) {
    int from, to;
    cin >> from >> to;
    from--, to--;
    if(from > to) {
      swap(from, to);
    }
    cout << f(from, to) << endl;
  }
  return 0;
}







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

using namespace std;

int main() {
    long long int x;
    cin >> x;
    long long int n=100;
    int count = 0;
    
    while(n < x){
        count++;
        n= n*1.01;
    }

    cout << count <<endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    int n;
    cin >>  n;
    vector <ll> v;
    for (int i=0;i<n;i++){
        ll p;
        cin >> p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    ll ans = 0;
    ans += v[0]/2;
    for (int i=1;i<v.size();i++){
        ans += v[i];
    }
    cout << ans << endl;
}

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

int main(){
    int n; 
    cin >> n;
    int t[n], m;
    for(int i=0; i<n; i++)
        cin >> t[i];
    cin >> m;
    int arr[m][2];
    for(int i=0; i<m; i++){
        for(int j=0; j<2; j++){
            cin >> arr[i][j];
        }
    }
    int sum=0;
    for(int j=0; j<n; j++){
        sum+=t[j];
    }
    for(int i=0; i<m; i++){
        int temp=sum;
        temp-=t[arr[i][0]-1];
        temp+=arr[i][1];
        cout << temp << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll k,a[200005],ans;
int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    
    for(int i=1; i<=n; i++)cin >> a[i];
    k=1;
    for(int i=n-1; i>=1; i--){
        if(a[i] >= a[i + 1])k++;
        else k = 1;
        ans = max(ans , k - 1);
    }
    
    cout << ans;
    
    
    
    return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.List

ans k xs rate
  | diff <= 0 = k * rate
  | otherwise = head xs * rate + ans diff (tail xs) (rate-1)
  where diff = k - head xs 

main :: IO ()
main = do
  [a, b, c, k] <- map read . words <$> getLine
  putStrLn $ show $ ans k [(a::Int),(b::Int),(c::Int)] 1


Measured memory_bytes: 3932
def dijkstra(v, G):
    import heapq

    ret = [10 ** 10] * len(G)
    ret[v] = 0
    q = [(ret[i], i) for i in range(len(G))]
    heapq.heapify(q)

    while len(q):
        tmpr, u = heapq.heappop(q)
        if tmpr == ret[u]:
            for w in G[u]:
                if ret[w] > ret[u] + 1:
                    ret[w] = ret[u] + 1
                    heapq.heappush(q, (ret[w], w))
    return ret


N, M = map(int, input().split())
G, ans = {i: [] for i in range(N)}, [-1] * N
for _ in range(M):
    A, B = map(int, input().split())
    G[A - 1].append(B - 1)
    G[B - 1].append(A - 1)

d = dijkstra(0, G)
for a in range(N):
    for b in G[a]:
        if d[a] - d[b] == 1:
            ans[a] = b + 1

print("Yes")
for a in ans[1:]:
    print(a)


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a == b && b == c) || (a!=b&&b!=c&&a!=c)){
        cout << "No";
    }
    else cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, k := nextInt(), nextInt()

	s := 0
	for i := 0; i < n; i++ {
		x := nextInt()
		s += 2 * min(x, k-x)
	}

	fmt.Println(s)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

int main(){
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for(int i=0; i<H; i++) cin >> S[i];

	vector<vector<int>> x(H, vector<int>(W)), y(H, vector<int>(W));

	for(int i=0; i<H; i++){
		int j=0;
		while(j<W){
			while(j<W&&S[i][j]=='#') j++;
			int k=j;
			while(k<W&&S[i][k]=='.') k++;
			int a = k-j;
			while(j<k) x[i][j++] = a;
		}
		debug(x[i]);
	}

	for(int i=0; i<W; i++){
		int j=0;
		while(j<H){
			while(j<H&&S[j][i]=='#') j++;
			int k=j;
			while(k<H&&S[k][i]=='.') k++;
			int a = k-j;
			while(j<k) y[j++][i] = a;
		}
	}

	int ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			ans = max(ans, x[i][j]+y[i][j]-1);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;string s;cin>>n>>s;
    vector< pair <int,int> > v(n);
    int b=0,w=0;
    for(int i=0;i<n;i++){
        if(s[i]=='.')w++;
        else b++;
        v[i]=make_pair(w,b);
    }
    int ans=1e6;
    for(int i=0;i<n;i++){
        int yay=v[i].second+v[n-1].first-v[i].first;
        ans=min(ans,yay);
    }
   ans=min(ans,v[n-1].first);
    cout<<ans;
}

Measured memory_bytes: 2180
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

L = [0] + L + [0]

su = 0
for i in range(N + 1):
    su += abs(L[i] - L[i + 1])

for i in range(1, N + 1):
    print(su + abs(L[i - 1] - L[i + 1]) - abs(L[i - 1] - L[i]) - abs(L[i] - L[i + 1]))

Measured memory_bytes: 13540
import java.io.*;
import java.util.*;
 
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String march = "MARCH";
    TreeMap<Character,Integer> mp = new TreeMap<Character, Integer>();
    for(int i = 0; i<5; i++){
      mp.put(march.charAt(i), 0); 
    }
    for(int i = 1; i<=N; i++){
      String s = sc.next();
      mp.put(s.charAt(0), mp.containsKey(s.charAt(0)) ? mp.get(s.charAt(0))+1 : 1);
    }
    long ans = 0;
    for(int i = 0; i<5; i++){
      for(int j = i+1; j<5; j++){
        for(int k = j+1; k<5; k++){
            ans += 1L * mp.get(march.charAt(i)) * mp.get(march.charAt(j)) * mp.get(march.charAt(k));
        }
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 48956
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int a, b; cin >> a >> b;
    if (a <= b) {
        REP(i, 0, b) cout << a;
        cout << endl;
    } else {
        REP(i, 0, a) cout << b;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

N = int(input())
inp = AC.inputStr(" ")
S = inp[0]
T = inp[1]

stack = ""

for i in range(N):
    stack = stack + S[i] + T[i]

print(stack)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue(){
	P x = Q[head];
	head = (head +1) % LEN;
	return x;
}

int min(int a,int b){
	return a<b ? a:b ;
}

int main(){
	int elaps = 0,c;
	int i,q;
	P u;
	
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1 ; tail=n+1 ;
	
	while(head != tail){
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0)enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 11840
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void print(int arr[], int n){
     for(int i=0;i<n;++i)
     cout<<arr[i]<<" ";
     cout<<endl;
}
int gcd(int a,int b){
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int32_t main()
{
    string s; cin>>s;
    int c=0;
    for(int i=0;i<(int)s.size()-1;++i){
        if(s[i]==s[i+1]){
            c++;
            int xp=s[i+1]-'0';
            xp=1-xp;
            s[i+1]=xp+'0';
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N;
	cin >> N;

	ll kotae = 1;
	ll mod = 1e9 + 7;

	rep1(i, N) {
		kotae = kotae * i % mod;
	}


	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H,W,D;
int32_t map[300][300];
int32_t n_to_pos[300*300+1][2];
int32_t reach_cost[300*300+1];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W>>D;
	for (int32_t i = 0; i < H; i++)
		for (int32_t j = 0; j < W; j++)
	{
		in >> map[i][j];
	}

	for (int32_t i = 0; i < H; i++)
		for (int32_t j = 0; j < W; j++)
	{
		n_to_pos[map[i][j]][0] = i;
		n_to_pos[map[i][j]][1] = j;
	}

	for (int32_t i = D+1; i <= H*W; i++)
	{
		reach_cost[i] = reach_cost[i - D] + std::abs(n_to_pos[i][0] - n_to_pos[i - D][0]) + std::abs(n_to_pos[i][1] - n_to_pos[i - D][1]);
	}

	int32_t Q;
	in >> Q;
	for (int32_t i = 0; i < Q; i++)
	{
		int32_t E, B;
		in >> B >> E;
		out << reach_cost[E] - reach_cost[B] << '\n';
	}


	return 0;
}
#endif


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

int main()
{
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    v.at(i) = i;
  }
  double sum = 0;
  long long nperm = 0;
  do {
    for (int k = 1; k < n; k++) {
      int i = v.at(k-1);
      int j = v.at(k);
      sum += sqrt((x.at(i)-x.at(j))*(x.at(i)-x.at(j)) + (y.at(i)-y.at(j))*(y.at(i)-y.at(j)));
    }
    nperm++;
  } while (next_permutation(v.begin(), v.end()));
  printf("%.10lf\n", sum / nperm);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#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(x) (x).begin(),(x).end()
signed main(){
    int n,m;
    cin>>n>>m;
    if(n==1&&m==1){
        cout<<1<<endl;
        return 0;
    }
    if(n==1||m==1){
        cout<<max(n,m)-2<<endl;
        return 0;
    }
    cout<<max(0LL,(n-2)*(m-2))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n;
  cin >> n;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  vector<ll> y = x;
  sort(ALL(y));
  ll lo = y[(n/2) - 1];
  ll hi = y[(n/2)];

  rep(i, n) {
    if (x[i] <= lo) cout << hi << endl;
    else cout << lo << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
object Main extends App{
    val Array(h, w) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val MM = Array.ofDim[Int](h, w)

    for(i<-0 until h){
    	MM(i) = scala.io.StdIn.readLine.toList.toArray.map{
    		case '#' => 1
    		case '.' => 0
    	}
    }

    var row = List[Int]()
    var col = List[Int]()

    for(i<-0 until w){
    	var tp = 0
    	for(j<-0 until h){
    		tp += MM(j)(i)
    	}
    	if(tp != 0){
    		row = i :: row
    	}
    }

    for(i<-0 until h){
    	if(MM(i).sum != 0){
    		col = i :: col
    	}
    }

    for(i<-col.sorted){
    	for(j<-row.sorted){
    		if(MM(i)(j) == 0){
    			print(".")
    		}else{
    			print("#")
    		}
    	}
    	print("\n")
    }

}

Measured memory_bytes: 30108
from sys import stdin

W, H, x, y, r = [int(x) for x in stdin.readline().rstrip().split()]

def isInner(px, py):
    if( px < 0 or px > W ):
        return False
    else: # x座標は長方形の内部
        if( py < 0 or py > H ):
            return False
        else:
            return True

if( isInner(x-r, y) and isInner(x+r, y) and isInner(x, y-r) and isInner(x, y+r) ):
    print("Yes")
else:
    print("No")



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

#define LL long long
#define REP(i, n) for(LL i = 0; i < (LL)(n); i++)
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

const LL mod = 1e9+7;

LL add(LL x, LL y) {
    return (x + y)%mod;
}
LL sub(LL x, LL y) {
    return (x - y + mod)%mod;
}
LL mul(LL x, LL y) {
    return ((x%mod)*(y%mod))%mod;
}
LL pw(LL x, LL y) {
    LL res = 1;
    while(y != 0) {
        if(y%2) {
            res = mul(x, res);
            y--;
        }else{
            x = mul(x, x);
            y /= 2;
        }
    }
    return res;
}
LL inv(LL x) {
    return pw(x, mod - 2);
}

int main() {
    LL H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<LL> fact(H + W + 1, 1);
    FOR(i, 1, H + W + 1) {
        fact[i] = mul(i, fact[i - 1]);
    }

    LL res = 0;
    REP(i, H - A) {
        LL d1 = mul(mul(fact[i + B - 1], inv(fact[i])), inv(fact[B - 1]));
        LL d2 = mul(mul(fact[H - i - 1 + W - B - 1], inv(fact[H - i - 1])), inv(fact[W - B - 1]));
        res = add(res, mul(d1, d2));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
/*
 this->author = Fuad Ashraful Mehmet, CSE-UAP
 Todo:
 lightoj : 1147,1101
 https://atcoder.jp/contests/abc174/tasks/abc174_f
*/
#include<bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define all(o) (o).begin(),(o).end()
#define dbg(o)  cerr<<"at "<<__LINE__<<" response = "<<o<<endl;
using namespace std;

const int N=5e5+5;
typedef  long long ll;
int n,m,k;
int bit[N];
int a[N];
vector<pair<int,int> > q[N];
int res[N],lst[N];

void add(int idx,int val)
{
      while(idx<N)
      {
            bit[idx]+=val;
            idx+=(idx&-idx);
      }
}

int query(int idx)
{
      int sum=0;
      while(idx>0)
      {
            sum+=bit[idx];
            idx-=(idx&-idx);
      }
      return sum;
}
void HalfDead()
{
      cin>>n>>k;
      for(int i=1;i<=n;++i)
      {
            cin>>a[i];
      }

      int l,r;
      for(int i=1;i<=k;++i)
      {
            cin>>l>>r;
            q[r].push_back(make_pair(l,i));
      }

      for(int i=1;i<=n;++i)
      {
            if(lst[a[i]])add(lst[a[i]],-1);
            lst[a[i]]=i;
            add(i,1);
            
            for(auto t:q[i])
            {
                  int idx=t.second;
                  res[idx]=query(i)-query(t.first-1);
            }
      }

      for(int i=1;i<=k;++i)
      {
            cout<<res[i]<<endl;
      }
}// end func
int main()
{
     ios_base::sync_with_stdio(0); cin.tie(nullptr);
      int tc=1;
      //cin>>tc;
      //scanf("%d",&tc);
     // cout<<fixed<<setprecision(10);
      while(tc--)
      {
            HalfDead();
      }
      return 0;
}

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

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

  // ここにプログラムを追記
  bool P, W, G, Y = false;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    
    if(S == "P"){
      P = true;
    }else if(S == "W"){
      W = true;
    }else if(S == "G"){
      G = true;
    }else{
      Y = true;
    }
  }
  
  if(P = true && W == true && G == true){
   if(Y == true){
     cout << "Four" << endl;
   }else{
     cout << "Three" << endl;
   }
  }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
long long int MOD = 998244353;
int N;
string gr[205];
int nums[205];
vi gra[205];
bool check=true;
int main () {
    cin>>N;
    rep(i,N)cin>>gr[i];
    rep(i,N){
        rep(j,N){
            if(gr[i][j]=='1'){
                gra[i].pb(j);
            }
        }
    }
    int ans=0;
    rep(now,N){
        rep(i,N)nums[i]=0;
        nums[now]=1;
        // bfs
        queue<int> Q;
        Q.push(now);
        while(!Q.empty()){
            int nownow=Q.front();
            Q.pop();
            rep(i,gra[nownow].size()){
                int nex=gra[nownow][i];
                if(nums[nex]==0){
                    nums[nex]=nums[nownow]+1;
                    Q.push(nex);
                }else if(abs(nums[nex]-nums[nownow])!=1){
                    check=false;
                    
                }
                
            }
            
        }
        if(!check){
            cout<<-1<<endl;
            return 0;
        }
        rep(i,N)ans=max(ans,nums[i]);
        //cout<<now<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
}

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int N,M,X,Y;
   cin>>N>>M>>X>>Y;
   vector<int>x(N),y(M);
   for(int i=0;i<N;i++)cin>>x[i];
   for(int i=0;i<M;i++)cin>>y[i];
   bool flg = false;
   for(int z=X+1;z<=Y;z++){
      bool x_ok = true;
      bool y_ok = true;
      for(int j=0;j<N;j++){
         if(z<=x[j])x_ok = false;
      }
      for(int j=0;j<M;j++){
         if(z>y[j])y_ok = false;
      }
      if(x_ok&&y_ok){
         flg=true;
         break;
      }
   }
   if(flg)cout<<"No War"<<endl;
   else cout<<"War"<<endl;
   return 0;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var s = nextstr(), t = nextstr();
  var ans = 1e9, sl = s.length, tl = t.length;
  for(var i = 0; i < sl-tl+1; i++){
    var a = tl;
    for(var j = 0; j < tl; j++){
      if(s[i+j] === t[j])a--;
    }
    if(ans > a)ans = a;
  }
  return ans;
}

Measured memory_bytes: 32144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char a,b,c;
    int f;
    while(scanf("%c %c",&a,&b)!=EOF)
    {
        f=1;
        if (a=='D') f=0;
        c='H';
        if (b=='D') c='D';
        if (f==0&&c=='D') c='H';
        else if (f==0&&c=='H') c='D';
        printf("%c\n",c);
        getchar();
    }
    return 0;
}

Measured memory_bytes: 128
//拓展欧几里得 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ll long long
inline int read()
{
	int s=0,w=1;register char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') { s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*w;
}
int main()
{
	int L=read(),R=read(),d=read();
	cout<<R/d-(L-1)/d<<endl;
	return 0;
}

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

int main() {
  string a;
  cin>>a;
  if(a.at(0)==a.at(1)&&a.at(1)==a.at(2))
    cout<< "Yes"<<endl;
  else if(a.at(3)==a.at(1)&&a.at(1)==a.at(2))
    cout<<"Yes"<<endl;
  
  
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(998244353)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int A, B;
    cin >> A >> B;
    Yes((A * B) % 2 == 1);
}


Measured memory_bytes: 256
def lcs(str1, str2):
    """文字列str1, str2の最長共通部分列(Longest Common Subsequence, LCS)を求める。
    計算量 O(|str1||str2|)
    """
    dp = [[0] * (len(str2) + 1) for _ in range(len(str1) + 1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if str1[i] == str2[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

    # 復元
    res = ''
    i, j = len(str1), len(str2)
    while i > 0 and j > 0:
        if dp[i][j] == dp[i - 1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j - 1]:
            j -= 1
        else:
            res = str1[i - 1] + res
            i -= 1
            j -= 1

    return res


s = input()
t = input()
print(lcs(s, t))

Measured memory_bytes: 144424
#include "bits/stdc++.h"
using namespace std;

int main() {
	int a[5], b[5], count = 0;
	bool check = true;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] % 10 == 0) count += a[i];
		else count += (a[i] / 10) * 10 + 10;
		b[i] = 9 - (a[i]  - 1) % 10;
	}
	sort(b, b + 5);
	cout << count - b[4];
}

Measured memory_bytes: 256
N = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(1,N+1):
  S = str(input())
  if S == "AC":
    ac += 1
  elif S == "WA":
    wa += 1
  elif S == "TLE":
    tle += 1
  else:
    re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))
  

Measured memory_bytes: 9204
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int judge(int, int, int, char, char str[16]);

int main()
{
	char str[16] = {0};

	while(scanf("%s", str) != EOF){

		if(judge(0,1,2,'o',str) == 1 || judge(3,4,5,'o',str) == 1 ||
			judge(6,7,8,'o',str) == 1 || judge(0,3,6,'o',str) == 1 ||
			judge(1,4,7,'o',str) == 1 || judge(2,5,8,'o',str) == 1 ||
			judge(0,4,8,'o',str) == 1 || judge(2,4,6,'o',str) == 1)
			printf("o\n");
		else if(judge(0,1,2,'x',str) == 1 || judge(3,4,5,'x',str) == 1 ||
			judge(6,7,8,'x',str) == 1 || judge(0,3,6,'x',str) == 1 ||
			judge(1,4,7,'x',str) == 1 || judge(2,5,8,'x',str) == 1 ||
			judge(0,4,8,'x',str) == 1 || judge(2,4,6,'x',str) == 1)
			printf("x\n");
		else
			printf("d\n");

	}
	return 0;
}

int judge(int a, int b, int c, char z, char str[16])
{
	if(str[a] == z && str[b] == z && str[c] == z)
		return 1;
	else
		return 0;
}

Measured memory_bytes: 524
#include <iostream>
using namespace std;
int main(){
  string word;
  char c = 'A';
  int circle = 'z'-'a'+1;
  cin >>word;

  int sum=0;
  int flag=0;
  for(int i=0; word[i]!='\0'; i++){
    if(word[i]==c)
      sum +=  circle;

      else{
        if(word[i]-c < 0)
          sum += circle-(c-'A')+(word[i]-'A');
        else
          sum += word[i]-c;

        c = word[i];
      }
    }

  cout << sum/circle << "\n";
}

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;


class UnionFindTree {
private:
	static const int MAX_N = 100002;
	int par[MAX_N], ran[MAX_N];

public:
	ll cnt[MAX_N];

	UnionFindTree(int n) {
		if (n > MAX_N) cerr << "INVALID INPUT" << endl;
		for (int i = 0; i < n; i++) {
			par[i] = i;
			ran[i] = 0;
			cnt[i] = 1;
		}
	}

public:
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}

public:
	ll unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return 0;

		if (ran[x] < ran[y]) {
			cnt[y] += cnt[x];
			par[x] = y;
			return cnt[y];
		}
		else {
			cnt[x] += cnt[y];
			par[y] = x;
			if (ran[x] == ran[y]) ran[x]++;
			return cnt[x];
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

UnionFindTree uft(100001);

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		cin >> q[i].first >> q[i].second;
		q[i].first--; q[i].second--;
	}
	vector<ll> ans(m);
	ll sum = (ll)n*(n - 1)/2;
	for (int i = m - 1; i >= 0; i--) {
		ans[i] = sum;
		int a = q[i].first, b = q[i].second;
		if (!uft.same(a, b)) {
			ll aa = uft.cnt[uft.find(a)], bb = uft.cnt[uft.find(b)];
			sum += aa * (aa - 1) / 2 + bb * (bb - 1) / 2;
			ll t = uft.unite(a, b);
 			sum -= t * (t - 1) / 2;
		}
	}
	for (int i = 0; i < m; i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4480
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N,M=map(int,input().split())
    if N>1:
        if M>1:
            print(N*(N-1)//2+M*(M-1)//2)
        else:
            print(N*(N-1)//2)
    else:
        if M>1:
            print(M*(M-1)//2)
        else:
            print(0)



resolve()

Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


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


int main() {
	ll D, N;
	cin >> D >> N;
	if (D == 0) {
		int k = N / 100;
		cout << N + k;
	}
	else if (D == 1) {
		if (N == 100)cout << 100 * 100 + 100;
		else cout << 100 * N;
	}
	else {
		if (N == 100)cout << 100 * 100 * 100 + 10000;
		else {
			ll k = pow(100, D);
			cout << k * N;
		}
	}
}


Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

int main()
{
	double l; cin >> l;
	double x = l / 3;
	double res = x * x*x;
	printf("%.10f", res);
}

Measured memory_bytes: 256
using System;
using System.Linq;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(input[i]);
    }
    int M = int.Parse(Console.ReadLine());
    for (int i = 0; i < M; i++) {
      input = Console.ReadLine().Split(' ');
      int P = int.Parse(input[0]);
      int X = int.Parse(input[1]);
      Console.WriteLine(arr.Sum() - (arr[P-1] - X));
    }
  }
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(void)
{
	char str[20];
	int  i = 0;
	
	scanf("%s", str);
	while (str[i++]);
	i -= 2;
	while (i >= 0){
		putchar(str[i--]);
	}
	puts("\0");
	
	return (0);
}

Measured memory_bytes: 524
#include <iostream>
#include <string>

using namespace std;

int field[8][8], first[2];

void searchFirstPlace();
int sumLine(int _line);

int main() {
	int sum;
	string str;
	char ans;

	while (1) {
		/*??\???*/
		for (int i = 0; i < 8; i++) {
			cin >> str;
			if (cin.eof()) break;

			for (int j = 0; j < 8; j++)
				field[i][j] = (str[j] == '1') ? 1 : 0;
		}
		if (cin.eof()) break;

		/*??????*/
		searchFirstPlace();
		sum = sumLine(first[1]);

		if (sum == 4) {
			ans = 'C';
		}
		else if (sum == 1) {
			if (sumLine(first[1] + 1) == 1)
				ans = 'B';
			else if (field[first[1] + 2][first[0] + 1] == 1)
				ans = 'F';
			else
				ans = 'D';
		}
		else {
			if (field[first[1] + 1][first[0]] == 0)
				ans = 'E';
			else if (field[first[1] + 1][first[0] + 1] == 0)
				ans = 'G';
			else
				ans = 'A';
		}

		/*??????*/
		cout << ans << endl;
	}

	return 0;
}

/*?????????????????¢??????1??????????????£?????????????????§?¨??????????*/
void searchFirstPlace() {
	bool flag = false;

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			if (field[i][j] == 1) {
				first[0] = j;
				first[1] = i;

				flag = true;
				break;
			}
		}
		if (flag) break;
	}
}

/*???????????°??¨??????????????????????????°?????????*/
int sumLine(int _line) {
	int ans = 0;

	for (int i = 0; i < 8; i++) {
		if (field[_line][i] == 1) {
			ans++;
		}
	}

	return ans;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int k;
    string s;
    cin>>k>>s;
    if(s.size()>k){
        rep(i,k) cout<<s[i];
        cout<<"..."<<endl;
    }
    else cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;
int main(){
  int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  string s;cin>>s;

  if(c > d){
    //追い越し確認
    bool oikosu = false;
    for(int i = b-2; d-1 > i; i++){
      if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
        oikosu = true;
        break;
      }
    }
    if(!oikosu){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = a; c-1 > i; i++){
    if(s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = b; d-1 > i; i++){
    if(s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n,d; cin >>n>>d;
  vector<ll> x(n);
  vector<ll> y(n);
  ll c=0;
  rep(i,n) {
    cin>>x[i]>>y[i];
  if(sqrt(x[i]*x[i]+y[i]*y[i])<=d)c++;
  }
  cout <<c<<endl;
}

Measured memory_bytes: 6492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, a, b);
	print((a * b & 1) ? "Odd " : "Even ");
	return 0;
}


Measured memory_bytes: 256