akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int a, b , d, r;
	double f;
	cin >> a;
	cin >> b;

	d = a / b;
	r = a%b;
	f = (double)a / (double)b;

	cout << d << " " << r << " ";
	cout<<fixed<< f << endl;

	return 0;
}

Measured memory_bytes: 3236
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
  }


  auto AA = A, BB = B;
  sort(all(AA));
  sort(all(BB), greater<int>());

  int ans;
  if (N % 2) {  // odd
    int mn = AA[N / 2], mx = BB[N / 2];
    ans = mx - mn + 1;
  } else {  // even
    int mn = AA[N / 2 - 1] + AA[N / 2];
    int mx = BB[N / 2 - 1] + BB[N / 2];
    ans = mx - mn + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9560
#include <stdio.h>

int main(void){
  int n, i, count = 0, now = 1;
  scanf("%d", &n);
  int b[n];
  for(i = 0; i < n; i++) scanf("%d", &b[i]);
  for(i = 0; i < n; i++){
    if(b[i] != now) count++;
    else now++;
  }
  if(now == 1) count = -1;
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 896
n, k = map(int, input().split())
boats = [set(list(map(int, input().split()))[1:]) for _ in range(k)]
r = int(input())
out = set()
for _ in range(r):
  p, q = map(int, input().split())
  for boat in boats:
    if p in boat and q in boat:
      out.add(p)
      out.add(q)
      break
print(len(out))


Measured memory_bytes: 5608
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int
	var s [][]string

	fmt.Scan(&h, &w)
	s = make([][]string, h)
	for i := 0; i < h; i++ {
		var tmp string
		fmt.Scan(&tmp)
		s[i] = strings.Split(tmp, "")
	}

	var res string
LABEL:
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == "#" {
				flag := 0
				if i != 0 {
					if s[i-1][j] == "#" {
						flag = 1
					}
				}
				if i != h-1 {
					if s[i+1][j] == "#" {
						flag = 1
					}
				}
				if j != 0 {
					if s[i][j-1] == "#" {
						flag = 1
					}
				}
				if j != w-1 {
					if s[i][j+1] == "#" {
						flag = 1
					}
				}
				if flag == 0 {
					res = "No"
					break LABEL
				}
			}
		}
	}

	if res == "No" {
		fmt.Println(res)
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 640
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int A, B, c = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    if (((i / 10000) == (i % 10)) && ((i % 10000) / 1000) == ((i % 100) / 10))
      c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3132
#include<iostream>

using namespace std;;

int main() {
	int n, h, w;
	cin >> w >> h >> n;
	int c[100][100],a[100],x[100],y[100],ans;
	ans = 0;
	for (int s = 0; s < w; s++) {
		for (int t = 0; t < h; t++) {
			c[s][t] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1) {
			for (int s = 0; s < x[i]; s++) {
				for (int t = 0; t < h; t++) {
					c[s][t] = 1;
				}
			}
		}
		if (a[i] == 2) {
			for (int s = x[i]; s <w; s++) {
				for (int t = 0; t < h; t++) {
					c[s][t] = 1;
				}
			}
		}if (a[i] == 3) {
			for (int s = 0; s < y[i]; s++) {
				for (int t = 0; t < w; t++) {
					c[t][s] = 1;
				}
			}
		}if (a[i] == 4) {
			for (int s = y[i]; s < h; s++) {
				for (int t = 0; t < w; t++) {
					c[t][s] = 1;
				}
			}
		}
	}
	for (int s = 0; s < w; s++) {
		for (int t = 0; t < h; t++) {
			if (c[s][t] == 0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*author:anshumanc007
   created on:05/01/2019
            */
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;


#define first fi
#define second se
typedef pair<long long int,long long int> pa;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int dp[MAX][2];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0;
    cin>>n;
    long long int A[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>A[i];
    }
    A[0]=INF;
    for(i=0;i<=n;i++)
    {
        dp[i][0]=INF;
        dp[i][1]=INF;
    }
    
     dp[1][0]=0;    
    for(i=2;i<=n;i++)
    {
        dp[i][0]=min(dp[i-1][1]+abs(A[i-1]-A[i]),dp[i-1][0]+abs(A[i-1]-A[i]));
        dp[i][1]=min(dp[i-2][1]+abs(A[i-2]-A[i]),dp[i-2][0]+abs(A[i-2]-A[i])) ;   
    }
    cout<<min(dp[n][0],dp[n][1]);
}

Measured memory_bytes: 2560
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int N; cin >> N;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) { cout << "Yes" << endl; return 0; }
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
h, w, n = map(int, input().split())
lst = []
for i in range(n):
    ai, bi = map(int, input().split())
    lst.append((ai, bi))

dic = {}
for i in range(10): dic[i] = 0
dic[0] = (h-2) * (w-2)
already = set([])
idx = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
for i in range(n):
    ai, bi = lst[i]
    for surround in idx:
        center = [ai+surround[0], bi+surround[1]]
        if min(center) < 2 or center[0] > h-1 or center[1] > w-1: continue
        cnt = 0
        for ind in idx:
            cell = (center[0]+ind[0], center[1]+ind[1])
            if cell in already: cnt += 1
        dic[cnt] -= 1
        dic[cnt+1] += 1
    already.add((ai, bi))

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

Measured memory_bytes: 66392
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int L[2*N+1];
	for(int i=0;i<2*N;i++)
	cin>>L[i];
	sort(L,L+2*N);
	int ans=0;
	for(int i=0;i<2*N;i+=2)
	ans+=L[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
local s=io.read():gsub("BC","D")
local counter=0
local answer=0
for i=1,#s do
    if s:byte(i)==65 then
        counter=counter+1
    elseif s:byte(i)==68 then
        answer=answer+counter
    else
        counter=0
    end
end
print(answer)

Measured memory_bytes: 3000
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		bitset<64> f;
		int q;
		cin >> q;
		while( q-- ) {
			int op, i;
			cin >> op;
			if( op <= 3 ) { cin >> i; }
			if( op == 0 ) { cout << f[i] << '\n'; }
			else if( op == 1 ) { f.set( i, true ); }
			else if( op == 2 ) { f.set( i, false ); }
			else if( op == 3 ) { f.flip( i ); }
			else if( op == 4 ) { cout << f.all() << '\n'; }
			else if( op == 5 ) { cout << f.any() << '\n'; }
			else if( op == 6 ) { cout << f.none() << '\n'; }
			else if( op == 7 ) { cout << f.count() << '\n'; }
			else if( op == 8 ) { cout << f.to_ullong() << '\n'; }
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}



Measured memory_bytes: 3228
#include <stdio.h>
#define N 100000
int partition(int*,int,int);
int main(){
  int n,i,q,A[N];

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

  q = partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i == q){
      printf("[%d]",A[i]);
    }
    else {
      printf("%d",A[i]);
    }
    if(i != n-1)printf(" ");
  }
  printf("\n");
  return 0;
}
int partition(int A[],int p,int r){
  int x,i,j,a;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      a = A[i];
      A[i] = A[j];
      A[j] = a;
    }
            }
  a = A[i+1];
  A[i+1] = A[r];
  A[r] = a;

  return i+1;
}






Measured memory_bytes: 2108
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
using namespace std;
  
#define int long long int 
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7; 

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define TC int t; cin >> t; while (t--) 

int ans(vi weights, vi values, int n, int w) {
    vi prev(w + 1), curr(w + 1);
    for(int i = 0 ; i < n; i++) {
        for(int j = 0 ; j <= w; j++) {
            if(weights[i] <= j) curr[j] = max(values[i] + prev[j - weights[i]], prev[j]);
        }
        prev = curr;
    }
    return prev[w];
}

void Panda() {
    int n, w;
    cin >> n >> w;
    vi weights, values;
    for(int i = 0, x, y; i < n; i++) {
        cin >> x >> y;
        weights.EB(x), values.EB(y);
    }
    cout << ans(weights, values, n, w) << endl;
}
  
int32_t main() {
 
    FAST;

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout); 
    
    Panda();

    return 0; 
} 

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  double sum = 0;
  for (int i = 0; i < N; i++)
  {
    double d = 1.0 / A[i];
    sum += d;
  }
  double ans = 1.0 / sum;
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a,b = [],[]
lisC = []
for i in range(n):
    tmp = list(int(i) for i in input().split())
    a.append(tmp[0])
    b.append(tmp[1])
    lisC.append((sum(tmp),i))
lisC = sorted(lisC)
res = 0
for i in range(n):
    if i%2==0:
        res += a[lisC[n-1-i][1]]
    else:
        res -= b[lisC[n-1-i][1]]
print(res)

Measured memory_bytes: 25788
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a - 1, b - 1)

# print(uf)
print(uf.group_count() - 1)

Measured memory_bytes: 75568
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[200000];
_int64 ans[200000];

int main()
{
  vector<pair<int,int> > aa;
  int i,n;
  _int64 now,nowind,nowcnt;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  aa.clear();
  for (i=0;i<n;i++)
    aa.push_back(make_pair(a[i],-i));
  sort(aa.begin(),aa.end());
  reverse(aa.begin(),aa.end());
  now=2000000000;nowind=-1;
  memset(ans,0,sizeof(ans));
  nowcnt=0;
  for (i=0;i<aa.size();i++)
  {
    if (nowind==-1)
    {
      nowind=-aa[i].second;now=aa[i].first;
      nowcnt++;
    }
    else
    {
      ans[nowind]+=nowcnt*(now-aa[i].first);
      now=aa[i].first;
      if (-aa[i].second<nowind) nowind=-aa[i].second;
      nowcnt++;
    }
  }
  ans[nowind]+=nowcnt*now;
  for (i=0;i<n;i++)
    printf("%lld\n",ans[i]);
  
  return 0;
}

Measured memory_bytes: 3956
import sys
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())

for i in range(n):
  b = int(input())
  for x in range(3):
    if a1[x] == b:
      a1[x] = 0
      break
  for y in range(3):
    if a2[y] == b:
      a2[y] = 0
      break
  for z in range(3):
    if a3[z] == b:
      a3[z] = 0
      break
#print(a1)
#print(a2)
#print(a3)
if sum(a1) == 0 or sum(a2) == 0 or sum(a3) ==0:
  print('Yes')
  sys.exit()

for i in range(3):
  w = a1[i] + a2[i] + a3[i]
  if w == 0:
    print('Yes')
    sys.exit()

if a1[0] + a2[1] + a3[2] == 0 or a1[2] + a2[1] + a3[0] == 0:
  print('Yes')
  sys.exit()
print('No')
  
      

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] dataList = Console.ReadLine().Split(' ');
            Console.WriteLine(dataList[2] + " " + dataList[0] + " " + dataList[1]);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	long long n, m;

	cin >> n >> m;

	//すでにi番目に行く道、またはi番目からNに行く道が見つかったか
	vector<bool> vis(n + 1, false);
	bool ans = false;

	for (long long i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1) {
			if (vis[b]) {
				ans = true;
			}
			vis[b] = true;
		}
		else if (b == n) {
			if (vis[a]) {
				ans = true;
			}
			vis[a] = true;
		}
	}


	if (!ans) cout << "IM";	

	cout << "POSSIBLE";
	return 0;

}


Measured memory_bytes: 256
_map = [200 for i in range(2020)]
n = int(input())
X = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))
for i in range(n):
    _map[X[i]] = i+1
for i in A:
    if _map.index(i)+1 < 2020 and _map[_map.index(i)+1] == 200:
        _map[_map.index(i)+1] = i
        _map[_map.index(i)] = 200
for i in range(n):
    print(_map.index(i+1))


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

char table[110][110];
bool usedh[110];
bool usedw[110];

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

    int H, W;
    cin >> H >> W;
    memset(usedh, 0, sizeof(usedh));
    memset(usedw, 0, sizeof(usedw));

    REP(h, H) {
        REP(w, W) {
            cin >> table[h][w];
            if (table[h][w] == '#') {
                usedh[h] = 1;
                usedw[w] = 1;
            }
        }
    }

    REP(h, H) {
        if (usedh[h] == 0) {
            continue;
        } else {
            REP(w, W) {
                if (usedw[w] == 0) {
                    continue;
                } else {
                    cout << table[h][w];
                }
            }
            cout << "\n";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
ls=[0]*(n+1)
for i in a:
    ls[i]+=1
ls=sorted(ls,reverse=True)
for i in range(k,n+1):
    if ls[i]==0:
        break
    else:
        cnt+=ls[i]
print(cnt)

Measured memory_bytes: 25876
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,k; cin >> n >> k;
    ll mn = min(n,k);
    vl v(n);
    rep(i,n) cin >> v[i];
    multiset<ll> st;
    ll mx = 0;
    rep(l,mn+1){
        rep(r,mn+1-l){
            rep(i,l) st.insert(v[i]);
            rep(j,r) st.insert(v[n-j-1]);
            ll rest = k - l - r;
            while(*st.begin()<0 && rest > 0){
                st.erase(st.begin());
                rest--;
            }
            ll sum = 0;
            for(auto i : st){
                //cout << i << endl;
                sum += i;
            }
            mx = max(mx, sum);
            st.clear();
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>

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

int main() {
	int N, M;
	cin >> N >> M;
	int A[8][8];
	int i;
	rep(i, N * N) {
		A[i / N][i % N] = 0;
	}
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		A[x - 1][y - 1] = 1;
		A[y - 1][x - 1] = 1;
	}
	int ans = 0;
	vector<int> v(N - 1);
	iota(v.begin(), v.end(), 1);
	do {
		if (A[0][v[0]] == 0)continue;
		for (i = 1; i < N - 1; i++)
			if (A[v[i - 1]][v[i]] != 1) 
				break;
		if (i == N - 1)ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
'''
N枚の皿それぞれにa_i個の寿司があり、等確率で皿を選んだ時その皿の寿司を一つ食べる。
その皿に寿司が無い場合は何も行わない。
すべての皿がなくなるまでの操作回数の期待値を求めよ。

terms:
    1<=N<=300
    1<=a_i<=3

input:
3
1 1 1

output:
    5.5

N<=300: O(N^3)が通る

期待値DP。
同じ寿司の量の皿の数にさえ注目すればいいところが鍵。
※PythonもPyPyも遅くて通らない...
再帰をfor文に書き直せばPyPyで通るはず
'''

from collections import defaultdict,deque
import sys, bisect, math, itertools
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


n = inp()
a = inpl()
'''
dp[i][j][k] : 
残り1個の皿がi枚、残り2個の皿がj枚、残り3個の皿がk枚の状態から
すべての寿司をなくすのに必要な回数の期待値
'''
one, two, three = 0, 0, 0
for i in a:
    if i == 1:
        one += 1
    elif i == 2:
        two += 1
    else:
        three+=1
MAX = max(one, two, three)
dp = [[[0.0] * (n + 1) for i in range(n + 1)] for j in range(n + 1)]

dp[0][0][0] = 1.0
for k in range(three+1):
    for j in range(two+three+1):
        for i in range(one+two+three+1):
            if i + j + k == 0 or i + j + k > n:
                continue
            res = 0.0
            if i != 0:
                res += dp[i - 1][j][k] * i
            if j != 0:
                res += dp[i + 1][j - 1][k] * j
            if k != 0:
                res += dp[i][j + 1][k - 1] * k
            res += n
            res *= 1.0 / (i + j + k)
            dp[i][j][k] = res
print(dp[one][two][three]-1.0)
# print(dp[one - 1][two - 1][three - 1])
# print(dp)
# @lru_cache(maxsize=None)
# def rec(i, j, k):
#     if i == 0 and j == 0 and k == 0:
#         return 0.0
    
#     res = 0.0
#     if i != 0:
#         res += rec(i - 1, j, k) * i
#     if j != 0:
#         res += rec(i + 1, j - 1, k) * j
#     if k != 0:
#         res += rec(i, j + 1, k - 1) * k
#     res += n
#     res *= 1.0 / (i + j + k)
#     return res

# print(rec(one, two, three))


'''
dp遷移は
次に引く皿の寿司 = 次の状態 × 確率 として
zero = dp[i][j][k] * (N-i-j-k)/N
one =  dp[i-1][j][k] * i/N
two =  dp[i+1][j-1][k] * j/N
three= dp[i][j+1][k-1] * k/N
dp[i][j][k]= zero + one + two + three + 1
(最後の1で追加しているイメージ)
となる。しかし両辺にdp[i][j][k]があると更新できない。(自己ループ)
よってこれをdp[i][j][k]について解くと
dp[i][j][k] = (one + two + three + 1)*N/(i+j+k)

dp[i][j][k] = (dp[i-1][j][k]*i + dp[i+1][j-1][k]*j + dp[i][j+1][k-1]*k + N)/(i+j+k)

ただし、それぞれが0の時に例外処理が必要。
'''

Measured memory_bytes: 254472
#include <iostream>

using namespace std;

const int MAX_N = 55, BLACK = 2, WHITE = 1;
int grid[MAX_N][MAX_N];

int all_neighbours_white(int row, int column)
{
    const int NO_OF_NEIGHBOURS = 4;
    int neighbour_x[NO_OF_NEIGHBOURS] = {-1, 0, 0, 1};
    int neighbour_y[NO_OF_NEIGHBOURS] = {0, 1, -1, 0};

    for(int i = 0; i < NO_OF_NEIGHBOURS; i++)
        if(grid[row + neighbour_x[i]][column + neighbour_y[i]] == BLACK)
            return false;

    return true;
}

int main()
{
    int height, width;
    cin >> height >> width;

    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            char block;
            cin >> block;

            grid[i][j] = (block == '#' ? BLACK : WHITE);


        }
    }

    int possible = true;
    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            if(grid[i][j] == BLACK && all_neighbours_white(i, j))
            {
                possible = false;
            }
        }
    }

    cout << (possible ? "Yes\n" : "No\n");

    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final int INF = 1 << 29;

	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int [][] data = new int[10][10];
			for(int i =0 ; i < 10 ;i++){
				for(int j = 0; j < 10; j++){
					if(i == j){
						data[i][j] = 0;
					}
					else{
						data[i][j] = INF;
					}
				}
			}
			for(int i = 0; i < n; i++){
				int from = sc.nextInt();
				int to = sc.nextInt();
				int value = sc.nextInt();
				data[from][to] = value;
				data[to][from] = value;
			}
			for(int j = 0; j < 10; j++){
				for(int i = 0; i < 10; i++){
					for(int k = 0; k < 10; k++){
						if(data[i][j] < INF && data[j][k] < INF)
						data[i][k] = Math.min(data[i][k], data[i][j] + data[j][k]);
					}
				}
			}
//			for(int i = 0; i < n; i++){
//				for(int j = 0; j < n; j++){
//					if(data[i][j] <= 600){
//						System.out.print(data[i][j] + " ");
//					}
//					else{
//						System.out.print("INF ");
//					}
//				}
//				System.out.println();
//			}

			int ind = 0;
			int ans = INF;
			for(int i = 0; i < 10 ; i++){
				int sum = 0;
				for(int j = 0; j < 10; j++){
					if(data[i][j] >= INF){
						continue;
					}
					sum += data[i][j];
				}
				if(sum == 0){
					continue;
				}
				if(ans > sum){
					ans = sum;
					ind = i;
				}
			}
			System.out.println(ind + " " + ans);

		}

	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     int a,b;
     cin >> a >> b;
     if(a==b)cout << "Draw";
     else if(a==1 || b==1){
        if(a==1)cout << "Alice";
        else cout << "Bob";
     }
     else{
        if(a>b)cout << "Alice";
        else cout << "Bob";
     }
  }


  int main(){
    IOS
       solve();
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 256
import Data.Char (ord,chr)

main = do
    line <- getLine
    putStrLn $ (cipher (-3) line)

cipher :: Int -> String -> String
cipher n = map (cipherChar n)

cipherChar :: Int -> Char -> Char
cipherChar n ch = chr (((ord ch) - base + n) `mod` 26 + base)
    where
    base = ord 'A'

Measured memory_bytes: 4008
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    string S;
    cin >> S;
    map<char, int> mp;
    rep(i, S.length()) {
        mp[S[i]]++;
        if (mp[S[i]] >= 2) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int n,a;
vector<int> v[100010];
bool f[100010]={};

int rec(int i){
    int b=0;
    vector<int> c;
    if(!f[i]) return 0;
    fr(j,v[i].size()) c.pb(rec(v[i][j]));
    sort(c.begin(),c.end());
    fr(j,v[i].size()){
        a=c[j]+v[i].size()-j;
        b=max(b,a);
    }
    return b;
}

int main(){
    cin>>n;
    Fr(i,n-1){
        cin>>a;
        v[a].pb(i+1);
        f[a]=1;
    }
    cout<<rec(1)<<endl;
}

Measured memory_bytes: 15232
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  LL N, K; cin >> N >> K;
  vector<LL> A(N); cin >> A;

  for (int i = K; i < N; ++i) {
    if (A[i-K] < A[i]) cout << "Yes" << endl;
    else               cout << "No" << endl;
  }
}


Measured memory_bytes: 4840
n = int(input())
ans = 10**9
for a in range(1,n):
    b = n - a
    a_sum = 0
    b_sum = 0
    for ai in str(a):
        a_sum += int(ai)
    for bi in str(b):
        b_sum += int(bi)
    v = a_sum+b_sum
    ans = min(ans,v)

print(ans)

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

int main(){
  string s;
  int count = 0;
  cin >> s;
  for(int i = 0;i < s.size()/2;i++){
  	if(s.at(i) != s.at(s.size()-1-i))
       count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll ;
const int MAX=1e3+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int dir[16][2]={{2,0},{0,2},{-2,0},{0,-2},{2,2},{-2,2},{2,-2},{-2,-2},
                {1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
int dir1[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

struct Node{
    int a,b;
    int ci;

    Node(int aa,int bb,int cc){
        a=aa;
        b=bb;
        ci=cc;
    }
    bool operator<(const Node &no)const {
        return ci>no.ci;
    }
};

char a[MAX][MAX];
bool biao[MAX][MAX];
int h,w;
bool check(int x,int y){
    if(x>=1&&x<=h&&y>=1&&y<=w){
        return true;
    }
    return false;
}
queue<Node>q;
queue<Node>q2;
void solve(){
    cin>>h>>w;
    int ch,cw,dh,dw;
    cin>>ch>>cw>>dh>>dw;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }

    q.push(Node(ch,cw,0));
    biao[ch][cw]=1;
    bool is=true;
    ll ans=-1;
    while(is&&(!q.empty()||!q2.empty())) {
        while (!q.empty()) {
            Node begin = q.front();
            q.pop();
            if (begin.a == dh && begin.b == dw) {
                ans = begin.ci;
                is = false;
                break;
            }
            for (int i = 0; i < 4; i++) {
                Node next = Node(begin.a + dir1[i][0], begin.b + dir1[i][1], begin.ci);
                if (a[next.a][next.b] == '#') {
                    q2.push(begin);
                }
                if (check(next.a, next.b) && biao[next.a][next.b] == 0 && a[next.a][next.b] == '.') {
                    biao[next.a][next.b] = 1;
                    q.push(next);
                }
            }
        }
        while (!q2.empty()) {
            Node begin = q2.front();
            q2.pop();
            if (begin.a == dh && begin.b == dw) {
                ans = begin.ci;
                is = false;
                break;
            }
            for (int i = -2; i <=2; i++) {
                for(int j=-2;j<=2;j++) {
                    Node next2 = Node(begin.a + i, begin.b + j, begin.ci + 1);
                    if (check(next2.a, next2.b) && biao[next2.a][next2.b] == 0 && a[next2.a][next2.b] == '.') {
                        biao[next2.a][next2.b] = 1;
                        q.push(next2);
                    }
                }
            }
        }
    }
    if(is){
        cout<<-1;
    }else{
        cout<<ans;
    }

}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 6052
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, m: usize, x: i64,
        ca: [(i64, [i64; m]); n],
    }
    const INF: i64 = 1 << 50;
    let mut mi: i64 = INF;
    for bits in 0..1 << n {
        let mut sum = vec![0; m];
        let mut cost = 0;
        for i in 0..n {
            let (c, ref a) = ca[i];
            if (bits & 1 << i) != 0 {
                cost += c;
                for j in 0..m {
                    sum[j] += a[j];
                }
            }
        }
        if sum.iter().all(|&y| y >= x) {
            mi = min(mi, cost);
        }
    }
    puts!("{}\n", if mi >= INF { -1 } else { mi });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int flag=0;
	for(int i=1;i<3000;i++)
	{
		if(i*8/100==a&&i/10==b){
			cout<<i;flag=1;
			break;
		}
	}
	if(flag==0)cout<<-1;
}

Measured memory_bytes: 256
// abc172_b
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>

#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
#define ULL unsigned long long
using namespace std;

int main(int argc, char const *argv[])
{
    string a, b;
    cin >> a >> b;
    uint c = 0;
    for (size_t i = 0; i < a.length(); i++)
        if (a[i] != b[i])
            c++;
    cout << c << endl;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
const int N = 1087, MOD = 1e9 + 7;
char g[N][N];
int dp[N][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> (g[i] + 1);
    dp[0][1] = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            dp[i][j] = (g[i][j] == '.' ? dp[i - 1][j] + dp[i][j -1] : 0) % MOD;
    cout << dp[n][m] << endl; 
}


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

int main(){
    long long n,m;
    bool check[100001];
    long long H[100001];
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>H[i];
        check[i]=true;
    }
    int A,B;
    for(int i=0;i<m;i++){
        cin>>A>>B;
        if(H[A]>H[B]){
            check[B]=false;
        }else if(H[A]<H[B]){
            check[A]=false;
        }else{
            check[A]=false;
            check[B]=false;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(check[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
  int64_t L = 1, l = 2;
  //L_n = L, L_n-1 = l
  for(int i; i < N; i++){
    int64_t tmp;
    tmp = L;
    L = L + l;
    l = tmp;
  }
  cout << l <<endl;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll n;
VL a;

signed main() {
    while(cin >> n) {
        if(n == 0) break;
        REP(i, n) a.emplace_back(IN());
        sort(All(a));
        ll ans = LINF;
        REP(i, n - 1) { ans = min(ans, a[i + 1] - a[i]); }
        cout << ans << "\n";
        a.clear();
    }
}



Measured memory_bytes: 3184
#include <stdio.h>
#include <stdlib.h>

int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int d;
d=c-b;

if(d<=0) puts("delicious");
else
if(d>0){
if(a>=abs(d))
puts("safe");
else
puts("dangerous");
}


return 0;
}


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

int main(void) {
  int l, r;
  string S, ans;
  cin >> S;
  
  l = (S[0]-'0')*10 + (S[1]-'0');
  r = (S[2]-'0')*10 + (S[3]-'0');
  
  if(l>0 && l<=12){
    if(r>0 && r<=12)
      ans = "AMBIGUOUS";
    else
      ans = "MMYY";
  }
  else{
    if(r>0 && r<=12)
      ans = "YYMM";
    else
      ans = "NA";
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = line[0], M = line[1];

            var array = new int[M][];

            for (var i = 0; i < M; i++)
            {
                array[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            var dict = new Dictionary<int, int>();
            foreach (var g in array.GroupBy(g => g[0]))
            {
                var count = 0;
                foreach (var c in g.OrderBy(o => o[1]))
                {
                    dict[c[1]] = ++count;
                }
            }

            for (var i = 0; i < M; i++)
            {
                Console.WriteLine("{0:d6}{1:d6}", array[i][0], dict[array[i][1]]);
            }
        }
    }
}


Measured memory_bytes: 39328
temparr = input()
temparr = temparr.split()
k = int(temparr[0])
n = int(temparr[1])
arr = []
temparr = input()
temparr = temparr.split()
for i in temparr:
    arr.append(int(i))
dp = [0 for _ in range(n + 2)]
arr = sorted(arr)
dp[0] = 0 
for i in range(1, n + 2):
    for j in arr:
        if j > i :
            continue 
        if dp[i - j] == 0 :
            dp[i] = 1 
            break 
if dp[n] == 1:
    print("First")
else:
    print("Second")


Measured memory_bytes: 79012
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, d;
    cin >> n >> d;
    vector<vector<int>> a(n, vector<int>(d));
    for(auto& x : a)
        for(auto& y : x)
            cin >> y;
    
    auto D = [d](vector<int>& x, vector<int>& y)->bool {
        double dist = 0;
        for(int i = 0; i < d; ++i)
            dist += pow((double)(x[i] - y[i]), 2);
        dist = sqrt(dist);
        return abs(dist - round(dist)) < 0.00000001;
    };

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < i; ++j) {
            ans += D(a[i], a[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
N=int(input())
T=list(map(int, input().split()))
M=int(input())
P = []
X = []
for i in range(M):
    a,b = map(int,input().split())
    P.append(a)
    X.append(b)
#print(T,sum(T))
#print(P)
#print(X)

for i in range(M):
  #print(i,T[P[i]-1],X[i])
  print(sum(T)-T[P[i]-1]+X[i])

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[1252525];
int ccnt[2525252];
int mcnt[2525252];
ll msum[2525252];
ll rmsum[1252525];

int main(){
  scanf("%d",&n);
  scanf("%s",s);
  REP(i,n)ccnt[i+1] = ccnt[i] + (int)(s[i]=='C');
  REP(i,n)mcnt[i+1] = mcnt[i] + (int)(s[i]=='M');
  REP(i,n)msum[i+1] = msum[i] + (s[i]=='C' ? mcnt[i] : 0);
  rmsum[n] = msum[n];
  FORR(i,0,n)rmsum[i] = s[i]=='C' ? msum[i+1] : rmsum[i+1];
  FOR(i,n,2*n+25){
    ccnt[i+1] = ccnt[i];
    mcnt[i+1] = mcnt[i];
    msum[i+1] = msum[i];
  }
  int q;
  scanf("%d",&q);
  while(q--){
    int k;
    scanf("%d",&k);
    ll ans = 0;
    REP(i,n)if(s[i]=='D'){
      ll mv = mcnt[i];
      int cc = ccnt[i+k] - ccnt[i];
      ll ms = (msum[i+k] - msum[i]) - mv*cc;
      ans += ms;
      // DEBUG(i);
      // DEBUG(mv);
      // DEBUG(cc);
      // DEBUG(msum[i+k]);
      // DEBUG(msum[i]);
      // DEBUG(ms);
    }
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int n, cnt=0;
    cin >> n;
    rep(i, n){
        int a;
        cin >> a;
        if(a%2 == 0){
            if(a%3 != 0 && a%5 != 0){
                cout << "DENIED" << endl;
                break;
            }
        }
        cnt ++;
        if(cnt == n){
            cout << "APPROVED" << endl;
        }
        
    }
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/11/03.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

struct ku{
    ll l;
    ll r;
};

int main(){
    int n;
    cin >> n;
    vector<ku> a(n);
    ll lma = 0, rmi = IINF + 1;
    rep(i, n){
        cin >> a[i].l >> a[i].r;
        lma = max(lma, a[i].l);
        rmi = min(rmi, a[i].r);
    }
    rep(i, n){
        if(a[i].l == lma && a[i].r == rmi){
            ll w = 0;
            rep(j, n) if(j != i) w = max(w, a[j].r - a[j].l + 1);
            cout << a[i].r - a[i].l + 1 + w << endl;
            return 0;
        }
    }
    vi idx(n);
    iota(all(idx), 0);
    int mai = -1, mii = -1;
    sort(all(idx), [&](int x, int y){
        if(a[x].l == a[y].l){
            return a[x].r > a[y].r;
        }
        return a[x].l > a[y].l;
    });
    mai = idx[0];
    sort(all(idx), [&](int x, int y){
        if(a[x].r == a[y].r){
            return a[x].l < a[y].l;
        }
        return a[x].r < a[y].r;
    });
    mii = idx[0];
    ll ans = 0;
    rep(i, n){
        if(i != mai && i != mii) ans = max(ans, max(0ll, a[mii].r - a[mai].l + 1) + a[i].r - a[i].l + 1);
    }
    vector<ku> b;
    rep(i, n){
        if(i != mai && i != mii && a[i].r < a[mai].r) b.push_back(a[i]);
    }
    n = b.size();
    if(n == 0){
        cout << max(ans, a[mai].r - a[mai].l + 1 + a[mii].r - a[mii].l + 1) << endl;
        return 0;
    }
    sort(all(b), [&](ku &x, ku &y){
        return x.r > y.r;
    });
    b.push_back({0, -1});
    priority_queue<pair<ll, int>> q;
    rep(i, n + 1) q.push({b[i].l, i});
    vi used(n + 1, false);
    int now = 0;
    ll r;
    ans = max(ans, a[mai].r - a[mai].l + 1 + max(0ll, a[mii].r - max(a[mii].l, q.top().first) + 1));
    while(now < n){
        r = b[now].r;
        while(1){
            if(b[now].r != r) break;
            used[now] = true;
            now++;
        }
        while(!q.empty()){
            if(!used[q.top().second]) break;
            q.pop();
        }
        if(q.empty()){
            ans = max(ans, max(0ll, r - a[mai].l + 1) + a[mii].r - a[mii].l + 1);
        }else{
            ans = max(ans, max(0ll, r - a[mai].l + 1) + max(0ll, a[mii].r - max(a[mii].l, q.top().first) + 1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7792
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[100];
int y[100];
int h[100];
int main() {
  string s;
  int ans = 1 << 30;
  cin >> s;
  rep(i, s.size() - 2){
    int tmp = stoi(s.substr(i, 3));
    int can = abs(tmp - 753) ;
    if(can < ans){
      ans = can;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256