akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  int max = 0;
  int c = 0;
  string tmp;
  
  for (int i = 0; i < N; i++)
  {
    tmp = s.at(i);
    c = 0;
    for (int j = 0; j < N; j++)
    {
      if( s.at(j) == tmp )
        c++;
    }
    for (int j = 0; j < M; j++)
    {
      if( t.at(j) == tmp )
        c--;
    }
    if (c > max)
    {
      max = c;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 256
import numpy as np  

n, k = map(int, input().split())
h = np.array([int(i) for i in input().split()])

dp = np.array([0] * n)

for i in range(1, n):
    j = max(0, i-k)
    dp[i] = np.min(dp[j:i] + abs(h[i] - h[j:i]))

print(dp[-1])



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

int main(){
    int N, Q;
    cin >> N >> Q;
    int a, b;
    vector<int> edge[N+1];
    long long X[N+1];

    rep(i, N){
        X[i+1] = 0;
    }

    rep(i, N-1){
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    long long p, x;

    rep(i, Q){
        cin >> p >> x;
        X[p] += x;
    }

    queue<int> que;
    que.push(1);
    long long check[N+1];
    rep(i, N){
        check[i+1] = 0;
    }
    check[1] = 1;

    while(!que.empty()){
        int j = que.front();
        que.pop();
        rep(i, edge[j].size()){
            int k = edge[j][i];
            if(check[k] == 0){
                que.push(k);
                X[k] += X[j];
                check[k] = 1;
            }
        }
    }

    rep(i, N){
        cout << X[i+1] << endl;
    }
}

Measured memory_bytes: 17908
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<pair<char, int> > p;
    vector<pair<char, int> > deck;
    char moji;
    for(int i = 0; i < 4; i++){
        if(i == 0){
            moji = 'S';
        }else if(i == 1){
            moji = 'H';
        }else if(i == 2){
            moji = 'C';
        }else{
            moji = 'D';
        }
        for(int j = 1; j <= 13; j++){
            deck.push_back(make_pair(moji, j));
        }
    }
    for(int i = 0; i < n; i++){
        char x;
        int y;
        cin >> x >> y;
        for(int j = 0; j < deck.size(); j++){
            if(deck[j].first == x && deck[j].second == y){
                deck.erase(deck.begin() + j);
            }
        }
        //p.push_back(make_pair(x, y));
    }
    for(int i = 0; i < deck.size(); i++){
        cout << deck[i].first << " " << deck[i].second << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  int a, b, k, max, min, i;

  scanf("%d %d %d", &a, &b, &k);

  if (a > b) {
    max = a;
    min = b;
  }else {
    max = b;
    min = a;
  }

  for (i = min; i > 0; i--) {
    if (max % i == 0 && min % i == 0) {
      k--;
    }
    if (k == 0) {
      printf("%d\n", i);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 128
words = lambda t : list(map(t, input().split()))
s = input()
rs = reversed(s)

a = []
cur_mod_10_pow = 1
v = 0
for i,c in enumerate(rs):
    if c == "?":
        a.append(cur_mod_10_pow)
    else:
        v += (int(c) * cur_mod_10_pow) % 13
        v %= 13
    cur_mod_10_pow *= 10
    cur_mod_10_pow %= 13

#print(v, list(reversed(a)))
MOD = 1000000007
prev = [0] * 13
prev[0] = 1
#print(prev)
for aa in a:
    cur = [0 for _ in range(13)]
    for i,p in enumerate(prev):
        #print(i,p, cur)
        for j in range(10):
            #print(i,j,(i+aa*j) % 13)
            cur[(i+(aa*j)) % 13] += p
            cur[(i+aa*j) % 13] %= MOD
    #print(cur)
    prev = cur

print(prev[(5-v)%13])


Measured memory_bytes: 45808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N;
  	int count=0;
  
  	cin >> N;
    vector<int> num(N);
  
  	for(int i=0; i<N; i++){
 		cin >> num.at(i);
    }
  
  while(true){
    bool fl = false;
    
  	for(int i=0; i<N; i++){
  		if(num.at(i) % 2 != 0){
          	fl = true;
        	//break;     
        }
    }
    
    if(fl)
      break;
    
    for(int i=0; i<N; i++){
  	  num.at(i) /= 2;
    }
    count++; 
  }
           
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
if subseqA[N] <= K:
    curABooks = N
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseqA[i] + subseqB[M] <= K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Measured memory_bytes: 129672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
bool ifPrime(ll x){
    bool res=true;
    for(ll i=2; i*i<=x; i++){
        if(x%i==0){res=false; break;}
    }
    return res;
}

int main(){
    ll n; cin>>n;
    ll res=0;
    rep(i,n){
        ll a; cin>>a;
        if(ifPrime(a)) res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 n,m;

vector<i64> a, b;

#include <vector>
#include <set>
using namespace std;

struct union_find {
  vector<int> par;
  vector<int> rank;
  union_find(int n) : par(n) , rank(n) {
    for(int i = 0;i < n;i++) par[i] = i;
  }
  int root(int i) {
    return par[i] == i ? i : par[i] = root(par[i]);
  }
  pair<int,int> unite(int x,int y) {
    x = root(x);
    y = root(y);
    if(x == y) return pair<int,int>(-1,-1);
    if(rank[x] < rank[y]) {
      par[x] = y;
      return {y , x};
    }
    else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
      return {x,y};
    }
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
};

int main() {
  cin >> n >> m;
  a.resize(m);
  b.resize(m);
  rep(i,0,m - 1) cin >> a[i] >> b[i];
  rep(i,0,m - 1) {
    a[i]--;
    b[i]--;
  }

  vector<i64> sz(n, 1);

  i64 ans = n * (n - 1) / 2;

  vector<i64> res;
  res.push_back(ans);

  union_find uf(n);

  for(int i = m - 1;i >= 1;i--) {
    i64 A = a[i];
    i64 B = b[i];
    if(!uf.same(A, B)) {
      auto p = uf.unite(A, B);
      int r = p.first;
      int c = p.second;
      ans -= sz[r] * sz[c];
      sz[r] += sz[c];
    }
    res.push_back(ans);
  }
  reverse(all(res));

  for(auto x: res) {
    cout << x << endl;
  }
}


Measured memory_bytes: 5364
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long double LD;

int main(int argc, char* argv[]) {
	LD l;
	cin >> l;
	LD a = l / 3, b = (l - a - a);
	LD ans = (a * a + 1.0e-18) * b;
	printf("%.9lf\n", (double)ans);
	return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  ll ans = 0;

  // vector<ll> list;
  for (ll i = 1; i <= N; i++) {
    ll v;
    scanf("%lld", &v);
    // list.emplace_back(v);

    if (i % 2 == 1 && v % 2 == 1) {
      ans++;
    }
  }

  cout << ans << endl;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];
    ll ans = 0;
    while(true){
        auto itr = max_element(a.begin(), a.end());
        if(*itr <= N-1) break;
        ll rem = *itr - (N - 1);
        ll red = (rem + N - 1)/N;
        *itr -= red * N;
        *itr -= red;
        ans += red;
        rep(i, 0, N) a[i] += red;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int a, b, c, d;
    while(cin >> a >> b >> c >> d) {
        if(a + b > c + d) cout << "Left" << endl;
        else if(a + b < c + d) cout << "Right" << endl;
        else cout << "Balanced" << endl;
    }
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	string a;
	cin >> a;

	int i = 0, j = n-1, ans = 0;
	while(i < j)
	{
		while(i < n && a[i] != 'W')
			i++;
		while(j >= 0 && a[j] != 'R')
			j--;

		if(i < n && j >= 0 && i < j && a[i] != a[j])
		{
			swap(a[i], a[j]);
			ans++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3744
import collections
n=int(input())
a_list=[int(i) for i in input().split()]

node1,node2=0,0
square=0

cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        square=max(square,k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(max(node1*node2,square))

Measured memory_bytes: 25500
S = input()
T =input()
min_e = 10000
for i in range(len(S) - len(T)+1):
    tmp_e=0
    for j in range(len(T)):
        if S[i+j] != T[j]:
            tmp_e += 1
    if tmp_e < min_e:
        min_e = tmp_e
print(min_e)

Measured memory_bytes: 67668
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int MOD = 998244353;
constexpr int N = 200000 + 100;

constexpr int modpow(int a, int n) {
    int rtn = 1;
    while (n > 0) {
        if (n & 1) rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

class Combination {
   private:
    vector<int> fact, rev_fact;

   public:
    Combination(int n) { setFact(n); }
    void setFact(int n) {
        fact.resize(n + 1);
        rev_fact.resize(n + 1);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= MOD;
        }
        rev_fact[n] = modpow(fact[n], MOD - 2);
        for (int i = n - 1; i >= 0; i--) {
            rev_fact[i] = rev_fact[i + 1] * (i + 1);
            rev_fact[i] %= MOD;
        }
    }
    int c(int n, int k) {
        if (k > n) return 0;
        return (((fact[n] * rev_fact[k]) % MOD) * rev_fact[n - k]) % MOD;
    }
    int h(int n, int k) { return c(n + k - 1, k); }
};

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

    int n, m, k;
    cin >> n >> m >> k;

    Combination combi(N);

    int ans = 0;

    for (int i = 0; i <= k; i++) {
        const int add =
            combi.c(n - 1, i) * m % MOD * modpow(m - 1, n - 1 - i) % MOD;
        ans = (ans + add) % MOD;
    }

    cout << ans % MOD << endl;
}


Measured memory_bytes: 6364
import sys
sys.setrecursionlimit(10**5+5)
input = sys.stdin.readline

N,M=map(int,input().split())
adj=[[] for _ in range(N)]

for i in range(M):
    x,y=map(int,input().split())
    x-=1
    y-=1
    adj[x].append(y)
    
dp=[0]*N#i番目絡みた最長経路

def rec(ii):
    new=0
    if len(adj[ii])==0:
        return 0
    for to in adj[ii]:
        if dp[to]!=0:
            new=dp[to]
        else:
            new=rec(to)
        dp[ii]=max(new+1,dp[ii])
    return dp[ii]
        
for i in range(N):
    rec(i)
    
print(max(dp))

Measured memory_bytes: 59008
// Vicfred
// https://atcoder.jp/contests/abc136/tasks/abc136_c
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const long n = readln.chomp.to!long;
    long[] h = readln.split.map!(to!long).array;

    long maxima = h[0] - 1;
    foreach(square; h) {
        if(square > maxima)
            square -= 1;

        if(square < maxima) {
            "No".writeln;
            return;
        }

        maxima = square;
    }

    "Yes".writeln;
}



Measured memory_bytes: 6212
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

std::vector<std::string> split(const std::string& input, char delimiter) {
	std::istringstream stream(input);
	std::string field;
	std::vector<std::string> result;
	while (std::getline(stream, field, delimiter)) {
		result.push_back(field);
	}
	return result;
}

int str_to_int(const std::string& s) {
	std::istringstream iss(s);
	int n;
	iss >> n;
	return n;
}

int main(void) {
	for (std::string s; std::getline(std::cin, s);) {
		const std::vector<std::string> ts = split(s, ' ');
		const int a = str_to_int(ts[0]), b = str_to_int(ts[2]);
		const char op = ts[1][0];
		if (op == '+') {
			std::cout << (a + b) << std::endl;
		} else if (op == '+') {
			std::cout << (a + b) << std::endl;
		} else if (op == '-') {
			std::cout << (a - b) << std::endl;
		} else if (op == '*') {
			std::cout << (a * b) << std::endl;
		} else if (op == '/') {
			if (b != 0) {
				std::cout << (a / b) << std::endl;
			}
		} else if (op == '?') {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
  int N,M,K;
  cin >> N >> M >> K;
  bool ans=false;
  for(int i=0; i<=N; i++){
    for(int j=0; j<=M; j++){
      if(i*(M-j)+(N-i)*j==K){
        ans=true;
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
};
int main(){
    int x,y; cin >> x >> y;
    if((x+y)%3!=0) cout << 0 << endl;
    else{
        int n=(x+y)/3;
        x-=n; y-=n;
        combination c(x+y);
        mint ans=c(x+y,x);
        cout << ans.x << endl;
    }
}

Measured memory_bytes: 10624
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Fri Feb  8 09:20:38 2019
//
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var N int
	fmt.Scan(&N)

	m := map[int]int{}
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		m[a]++
	}

	ans := 0
	for k, v := range m {
		if v-k < 0 {
			ans += v
		} else {
			ans += min(v, v-k)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8960
#include <complex>
#include <iostream>
#include <vector>
using namespace std;

vector<complex<double> >A;
complex<double>v1, j = sqrt(-1), p1, p2,v,p3,p4;
double a,b;
int n;
int f(int m){
	int i;
	double c = acos(a / 2);
	p3 = polar(1.0,b+c) + p1;
	p4 = polar(1.0,b-c) + p1;
	int s1 = 2, s2 = 2;
	for (i = 0; i < n; i++){
		if (A[i] == p1 || A[i] == p2)continue;
		if (abs(A[i] - p3) - 1 < 1e-6){
			s1++;
		}
		if (abs(A[i] - p4) - 1 < 1e-6){
			s2++;
		}
	}
	if (m<s1)m = s1;
	if (m<s2)m = s2;
	return m;
}
int main(){
	int m,i,i1;
	char c;
	while (cin >> n,n!=0){
		A.clear();A.resize(n);
		for (i = 0; i < n; i++){
			cin >> a >> c >> b;
			A[i] = complex<double>(a, b);
		}
		m = 1;
		for (i = 0; i < n; i++){
			p1 = A[i];
			for (i1 = i+1; i1 < n; i1++){
				p2 = A[i1];
				v = p2 - p1;
				a = abs(v);
				b = arg(v);
				if (a <= 2){
					m = f(m);
				}
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1352
#include<stdio.h>
 
int main()
{
  char s[16];
  scanf("%s", s);
  int len = strlen(s);
  int rc = 1;
  int i, cnt;

  if (s[0] != 'A')
    rc = 0;

  cnt = 0;
  for (i = 1; i < len; i++) {
    if (s[i] <= 'Z') {
      if (i == 1 || i == len -1) {
        rc = 0;
      } else if (s[i] == 'C') {
        cnt++;
      }
    }
  }

  if (cnt != 1)
    rc = 0;

  printf(rc == 0 ? "WA" : "AC");
  return 0;
}

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

using namespace std;

typedef long long int ll;

bool vis[200005];
ll cc =0;
void DFS(vector<int> adj[] , int s)
{
    vis[s]=1;
    cc++;
    for(int i=0 ;i<adj[s].size();  i++)
    {
        if(!vis[adj[s][i]])
            DFS(adj,adj[s][i]);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,m;
    cin >> n >> m;

    map<pair<int,int>,bool> mp;
    vector<int> adj[n+1];

    for(int i=0 ; i<m ;i++)
    {
        int u,v;
        cin >> u >> v;
        if(mp.find({u,v}) != mp.end())
            continue;
        adj[u].push_back(v);
        adj[v].push_back(u);
        mp[{u,v}] =1;
        mp[{v,u}] =1;
    }

    ll ans = 0;
    for(int i=1 ; i<=n ; i++)
    {
        if(!vis[i])
        {
            cc =0;
            DFS(adj,i);
            ans = max(cc,ans);
        }
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 49120
#include<bits/stdc++.h>
using namespace std;
 
int main() 
{
	string n;
	long long int ans = 0;
	cin >> n;
	
	for(int i = 0; i<n.size(); i++)
		ans += (n[i] - '0');
	
	cout << (ans % 9 == 0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;

unordered_map<ll, vector<ll>> G;

void search(ll node, ll d, vector<ll>& dist) {
    if (dist[node] <= d) {
        return;
    }

    dist[node] = d;

    for (auto next : G[node]) {
        search(next, d + 1, dist);
    }
}

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

    ll N;
    cin >> N;
    for (ll i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<ll> fennec(N + 1, INF);
    search(1, 0, fennec);

    vector<ll> snuke(N + 1, INF);
    search(N, 0, snuke);

    ll fennec_node = 0, snuke_node = 0;
    for (ll i = 1; i <= N; i++) {
        if (fennec[i] <= snuke[i]) {
            fennec_node++;
        } else {
            snuke_node++;
        }
    }

    cout << (fennec_node > snuke_node ? "Fennec" : "Snuke") << endl;

    return 0;
}



Measured memory_bytes: 16932
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    ll n, t, ans = 0, tmp;
    cin >> n >> t;
    vector<ll> T;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        T.push_back(tmp);
    }
    T.push_back(1LL<<58);
    for (int i = 0; i < n; i++) {
        ans += min(T[i+1]-T[i], t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{

	std::ios::sync_with_stdio(false);
	char ch;
	cin >> ch;

	int val = (int)ch;
	if (val <= (int)'z' && val >= (int)'a')cout << 'a';
	else cout << 'A';
	// cout <<  << ;
	return 0;
}

Measured memory_bytes: 3664
n,a,b,c = map(int,input().split())
s = [input() for _ in range(n)]
c2v = {'A':a,'B':b,'C':c}
sum_v = sum(c2v.values())
if sum_v == 0:
    print('No')
    exit()
if sum_v == 1:
    ans = []
    for ss in s:
        if c2v[ss[0]] == 0 and c2v[ss[1]] == 0:
            print('No')
            exit()
        elif c2v[ss[0]] == 0 and c2v[ss[1]] == 1:
            ans.append(ss[0])
            c2v[ss[0]] += 1
            c2v[ss[1]] -= 1
        elif c2v[ss[0]] == 1 and c2v[ss[1]] == 0:
            ans.append(ss[1])
            c2v[ss[1]] += 1
            c2v[ss[0]] -= 1
    print('Yes')
    for ans_i in ans:
        print(ans_i)

if sum_v >= 2:
    ans = []
    for ss_i,ss in enumerate(s):
        if c2v[ss[0]] == 0 and c2v[ss[1]] == 0:
            print('No')
            exit()
        elif c2v[ss[0]] == 0 and c2v[ss[1]] >= 1:
            ans.append(ss[0])
            c2v[ss[0]] += 1
            c2v[ss[1]] -= 1
        elif c2v[ss[0]] >= 1 and c2v[ss[1]] == 0:
            ans.append(ss[1])
            c2v[ss[1]] += 1
            c2v[ss[0]] -= 1
        else: # どっちから引いてもとりあえず大丈夫な場合は次のターンでダメな状態、（0,0）に陥らないように次に出てくる方に加算する。
            if ss_i+1 == n: # 最後だから適当でいい
                ans.append(ss[0])
                c2v[ss[0]] += 1
                c2v[ss[1]] -= 1
                continue
            next_ss = s[ss_i+1]
            if ss[0] in next_ss:
                ans.append(ss[0])
                c2v[ss[0]] += 1
                c2v[ss[1]] -= 1
            else:
                ans.append(ss[1])
                c2v[ss[1]] += 1
                c2v[ss[0]] -= 1
    print('Yes')
    for ans_i in ans:
        print(ans_i)








Measured memory_bytes: 86256
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
vector<int> vertexs[200000];
int visited[200000] = {};
int main() {
#define int long long
	int n, m;
	cin >> n >> m;
	visited[1] = 1;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	queue<int> next;
	next.push(1);
	while (next.empty() == false) {
		int now = next.front();
		next.pop();
		for (int i = 0;i < vertexs[now].size();++i) {
			if (visited[vertexs[now][i]] == 0) {
				visited[vertexs[now][i]] = ((visited[now]) % 2) + 1;
				next.push(vertexs[now][i]);
			}
			else if (visited[vertexs[now][i]] % 2 != (visited[now] + 1) % 2) {
				cout << n*(long long)(n - 1) / (long long)2 - m << endl;
				return 0;
			}
		}
	}
	long long a = 0, b = 0;
	for (int i = 1;i <= n;++i) {
		if (visited[i] == 1) a++;
		else b++;
	}
	cout << a*b - m << endl;
	return 0;
}

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

int main(){
  int n;
  int* m;
  int list[1000][3];
  cin>>n;
  for(int i=0;i<n;i++){
  cin>>list[i][0]>>list[i][1]>>list[i][2];
  }
  for(int j=0;j<n;j++){
  sort(list[j],list[j]+3);
  if(list[j][0]*list[j][0]+list[j][1]*list[j][1]==list[j][2]*list[j][2]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
S = list(input())
l = len(S)

def judge(arr):
  l = len(arr)
  if len(arr) % 2 != 0:
    l = len(arr)
  for i in range(int(l/2)):
    if arr[i] != arr[l-1-i]:
      print("No")
      exit()
      
judge(S)
center = int((l-1)/2)
judge(S[0:center])
judge(S[center+1:])
print("Yes")

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


def main():
    """Function."""
    k, s = map(int, input().split())

    counter = 0
    for x in range(k+1):
        for y in range(k+1):
            z = s - (x + y)
            if z >= 0 and k >= z:
                counter += 1
    print(counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();
		int cnt=0;
		for(int i=0;i<s.length();i++)if(s.charAt(i)=='o')cnt++;
		System.out.println(700+100*cnt);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ps push_back
using namespace std;
void solve()
{

}
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    long long n, m;
    cin>>n>>m;
    m*=m;
    int ans=0;
    for(int i=0; i<n; i++)
    {
        long long  x, y;
        scanf("%lld%lld", &x, &y);
        if(x*x+y*y<=m)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3756
#include <iostream>

using ll = long long;

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

int main() {
  ll n, a, b;
  std::cin >> n >> a >> b;

  ll c = n / (a + b);
  ll ans = a * c + std::min(a, n % (a + b));

  std::cout << ans << '\n';

  return 0;
}


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

int main(){
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<sqrt(n)+1;i++){
		if(n%i==0)ans=i;
	}
	puts(ans+n/ans-2);
}

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

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        sc.nextLine();

        int a[] = new int[N];
        int b[] = new int[M];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        sc.nextLine();

        for (int i = 0; i < M; i++) {
            b[i] = sc.nextInt();
        }
        Arrays.sort(b);
        sc.close();

        if (X >= Y) {
            System.out.println("War");
        } else if (a[N - 1] < b[0] && X < a[N - 1] && Y > b[0]) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

int main()
{
    int x[5];
    int i;

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

    for (i = 0; i < 5; i++)
    {
        if (x[i] == 0)
            break;
    }

    printf("%d\n", i + 1);
    return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += a[i] * a[j];
		}
	}
	cout << ans;
	return 0;	
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())
S = []
for i in range(H):
	s = list(map(int, list(input())))
	S.append(s)
A = [[0 for i in range(W+1)] for j in range(H+1)]
for i in range(H):
	for j in range(W):
		A[i+1][j+1] = A[i+1][j] + A[i][j+1] - A[i][j] + S[i][j]

def f(x1,y1,x2,y2):
	return A[x2][y2] - A[x1-1][y2] - A[x2][y1-1] + A[x1-1][y1-1]

if f(1,1,H,W) <= K:
	print(0)
	exit()

m = 100000

def int2bit(n):
	ret = [0 for i in range(H-1)]
	c = 0
	while n > 0:
		ret[c] = n % 2
		n = n // 2
		c += 1
	return ret

def getx1x2(b):
	ret = []
	x1 = 1
	for i in range(H-1):
		if b[i] == 1:
			ret.append((x1, i+1))
			x1 = i+2
	ret.append((x1, H))
	return ret

def check(x1x2):
	for y in range(1, W+1):
		for x1, x2 in x1x2:
			if(f(x1,y,x2,y) > K):
				return False
	return True

for i in range(2**(H-1)):
	x1x2 = getx1x2(int2bit(i))
	if not check(x1x2):
		continue
	cnt = len(x1x2) - 1
	y1 = 1
	for y2 in range(2, W+1):
		flag = False
		for x1, x2 in x1x2:
			if f(x1,y1,x2,y2) > K:
				flag = True
				break
		if flag:
			y1 = y2
			cnt += 1
	m = min(m, cnt)
print(m)

Measured memory_bytes: 46172
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
const int N=4e5+9;
const double pi=acos(-1);
using namespace std;
struct node{
	int x,y;
}a[N],b[N];
int sx,sy,tx,ty,n,tot,f[N],t[N];
int cmp2(node a,node b){return a.x<b.x;}
void work1()
{
	for(int i=1;i<=n;++i) 
	 if(a[i].x>=sx&&a[i].y<=ty&&a[i].x<=tx&&a[i].y>=sy) 
	   b[++tot]=a[i];
	sort(b+1,b+tot+1,cmp2); 
	memset(t,127/10,sizeof(t));
	t[0]=0;
	int maxx=0,num=0;
	for(int i=1;i<=tot;++i)
	{
		int l=0,r=maxx,mid=0;
	    while(l<r)
	    {
	      mid=(l+r+1)/2;
	      if(t[mid]<b[i].y) l=mid;
		  else r=mid-1;	
		}
		f[i]=l+1;
		t[l+1]=min(t[l+1],b[i].y);
        maxx=max(maxx,l+1);
	    if(b[i].y<=ty) num=max(num,f[i]);
	}
if(num==0)
{
	printf("%.15lf",(double)(tx-sx)*100+(ty-sy)*100.0);
	return;
}
    if(num==(min(tx-sx,ty-sy)+1))
      printf("%.15lf",(double)(tx-sx)*100+(double)(ty-sy)*100-num*20.0+num*0.5*10*pi+0.5*10*pi);
    else 
     printf("%.15lf",(double)(tx-sx)*100+(double)(ty-sy)*100-num*20.0+0.5*10*num*pi);
}
void work2()
{
	for(int i=1;i<=n;++i)  
	  a[i].x=a[i].x-(a[i].x-sx)*2; 
	tx=tx-(tx-sx)*2;
	for(int i=1;i<=n;++i) 
	 if(a[i].x>=sx&&a[i].y<=ty&&a[i].x<=tx&&a[i].y>=sy) 
	   b[++tot]=a[i];
	sort(b+1,b+tot+1,cmp2);
	memset(t,127/10,sizeof(t));
	t[0]=0; 
	int maxx=0,num=0;
	for(int i=1;i<=tot;++i)
	{
		int l=0,r=maxx,mid=0;
	    while(l<r)
	    {
	      mid=(l+r+1)/2;
	      if(t[mid]<b[i].y) l=mid;
		  else r=mid-1;	
		}
		f[i]=l+1;
		t[l+1]=min(t[l+1],b[i].y);
        maxx=max(maxx,l+1);
	    if(b[i].y<=ty) num=max(num,f[i]);
	}
if(num==0)
{
	printf("%.15lf",(tx-sx)*100.0+(ty-sy)*100.0);
	return;
}
    if(num==(min(tx-sx,ty-sy)+1))
      printf("%.15lf",(tx-sx)*100.0+(ty-sy)*100.0-num*20.0+num*0.5*10*pi+0.5*10*pi);
    else 
     printf("%.15lf",(tx-sx)*100.0+(ty-sy)*100.0-num*20.0+0.5*10*num*pi);
}
int main()
{
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    scanf("%d",&n);
	for(int i=1;i<=n;++i)	scanf("%d%d",&a[i].x,&a[i].y);
	if(sx<=tx&&sy<=ty) {work1();return 0;}
	if(sx>=tx&&sy<=ty) {work2();return 0;}
	if(sx<=tx&&sy>=ty) {swap(sx,tx);swap(sy,ty);work2();return 0;}
	if(sx>=tx&&sy>=ty) {swap(sx,tx);swap(sy,ty);work1();return 0;}
}
/*
0 0 2 1
3
0 1
3 3
2 0
*/


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

bool solve() {
    vector<ll> A(5);
    for ( int i = 0; i < 5; i++ ) cin >> A[i];
    ll K;
    cin >> K;
    return (A[4]-A[0]) > K;
}

int main() {
    string ans = solve() ? ":(" : "Yay!";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define INF 10000000
#define NIL -1
#define BLACK 2
#define WHITE 0
#define GRAY 1
#define MAX 100
using namespace std;

int color[MAX]={},d[MAX]={},pi[MAX]={},n;

int prim(int w[MAX][MAX]){
    int u,i,v,mincost;
    for(u=0;u<n;u++){
        d[u]=INF;
        pi[u]=NIL;
        color[u]=WHITE;
    }
    d[0]=0;
    while(1){
        mincost = INF;
        u=-1;
        for(i=0;i<n;i++){
            if(color[i]!=BLACK&&d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(u==-1)break;
        color[u]=BLACK;
        for(v=0;v<n;v++){
            if(color[v]!=BLACK&&w[u][v]!=INF){
                if(d[v]>w[u][v]){
                    pi[v]=u;
                    d[v]=w[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    int sum=0;
    for(i=0;i<n;i++){
        if(pi[i]!=NIL)sum+=w[i][pi[i]];
    }
    return sum;
}

int main(){
    int w[MAX][MAX],i,j;
    cin>>n;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cin>>w[i][j];
            if(w[i][j]==-1)w[i][j]=INF;
        }
    }
    cout<<prim(w)<<endl;
}


Measured memory_bytes: 3096
use std::io::*;
use std::str::*;
use std::f64::consts::*;
use std::f64;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        k: i32,
        v: [i32; n],
    }
    let mut sum = 0;
    for i in 0..n {
        if (k - v[i] < v[i]) {
            sum += (k - v[i]) * 2;
        } else {
            sum += v[i] * 2;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int a, b;
	cin >> a >> b;
	if (a < 6)
	{
		b = 0;
	}
	else if (a < 13)
	{
		b /= 2;
	}
	cout << b << endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+1)
for i in range(N):
  L[i+1]=L[i]+A[i]
result = 0
L_s = set(L)
D = {l:0 for l in L_s}
for l in L:
  D[l] += 1
for v in D.values():
  result += v*(v-1)//2
print(result)  

Measured memory_bytes: 54532
n = STDIN.gets.chomp.to_i
input = []
ans = 0
for i in 0...n
  input[i] = STDIN.gets.chomp.split(//).sort.join
end
x = input.group_by do |i| i end
x.count {|k,v|
  if v.size > 1
    for j in 1...v.size
      ans += j
    end
  end
}
puts ans

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


int main() {
    string s;cin >> s;
    int a,z;
    a = 0;
    z = 0;
    for (int i = 0;i < s.size();i++){
        char c = s.at(i);
        if (c == 'A'){
            if (a == 0){
                a = i+1;
            }
        }
        if (c == 'Z'){
            z = i+1;
        }
    }
    cout << z-a+1 << endl;

}       

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cassert>
#include <map>
using namespace std;

struct Node {
  Node *left, *right;
};
typedef pair<Node*, int> value;

value parse(const string &s, int idx = 0) {
  assert(s[idx] == '(');
  assert(idx < s.length()-1);
  Node *ret = new Node();
  int nidx;
  if (s[idx+1] == ',') {
    ret->left = NULL;
    if (s[idx+2] == ')') {
      nidx = idx+3;
      ret->left = ret->right = NULL;
    } else {
      value rv = parse(s, idx+2);
      ret->right = rv.first;
      nidx = rv.second+1;
    }
  } else {
    value lv = parse(s, idx+1);
    ret->left = lv.first;
    if (s[lv.second+1] == '(') {
      value rv = parse(s, lv.second+1);
      ret->right = rv.first;
      nidx = rv.second+1;
    } else if (s[lv.second+1] == ')') {
      ret->right = NULL;
      nidx = lv.second+2;
    }
  }
  return make_pair(ret, nidx);
}

Node* intersect(Node *t1, Node *t2) {
  if (t1 == NULL || t2 == NULL) {
    return NULL;
  }
  Node *r = new Node();
  r->left = intersect(t1->left, t2->left);
  r->right = intersect(t1->right, t2->right);
  return r;
}
Node* uni(Node *t1, Node *t2) {
  if (t1 == NULL && t2 == NULL) return NULL;
  Node *r = new Node();
  if (t1 == NULL) r = t2;
  else r = t1;
  r->left = uni((t1==NULL)?NULL:t1->left, (t2==NULL)?NULL:t2->left);
  r->right = uni((t1==NULL)?NULL:t1->right, (t2==NULL)?NULL:t2->right);
  return r;
}

void print(Node *t) {
  if (t == NULL) return;
  cout<<"("; print(t->left); cout<<","; print(t->right); cout<<")";
}

int main() {
  string op, s1, s2;
  while(cin>>op) {
    cin>>s1>>s2;
    Node *t1 = parse(s1).first;
    Node *t2 = parse(s2).first;
    if (op == "i") {
      t1 = intersect(t1, t2);
    } else {
      t1 = uni(t1, t2);
    }
    print(t1); cout<<endl;
  }
}

Measured memory_bytes: 1204
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl '\n';
#define all(v) ((v).begin()), ((v).end())
#define sz(s)               (int)s.size()
#define Ceil(x,y)             ((x+y-1)/y)
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define vi                    vector<int>
#define pii                 pair<int,int>
#define fx(n)           fixed<<setprecision(n)
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, MOD = 1e9 + 7;
using namespace std;
void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); }
int main()
{
	fast();
	vector<ll>v(3);
	for(int i=0;i<3;i++)
        cin>>v[i];
    sort(all(v));
    if(v[0]==5 && v[1]==5 &&v[2]==7)
        cout<<"YES\n";
    else
    cout<<"NO\n";

	return 0;
}


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

cnt = [[0]*10 for i in range(10)]
# print(cnt)

for i in range(1,N+1):
    s = int(str(i)[0])
    e = int(str(i)[-1])
    cnt[s][e] += 1

result = 0
for j in range(10):
    for k in range(10):
        result += cnt[j][k] * cnt[k][j]

print(result)


Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

void dfs(ll v, vector<vector<ll>>& adj, vector<bool>& vis)
{
    vis[v] = 1;
    for(auto u : adj[v])
    {
        if(vis[u]) continue;
        dfs(u,adj,vis);
    }
}

int main()
{
    ll n,m,i,j;
    cin>>n>>m;
    vector<vector<ll>> adj(n+1);
    for(i=0;i<m;i++)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll cc = 0;
    vector<bool> vis(n+1,false);
    for(i=1;i<=n;i++)
    {
        if(vis[i]) continue;
        cc++;
        dfs(i,adj,vis);
    }
    cout<<cc-1;
}

Measured memory_bytes: 10320
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
long double dist(int x1,int y1,int x2,int y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
int fact(int x){
	int res = 1;
	for(int i=1;i<=x;i++){
		res *= i;
	}
	return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		v[i] = i;
	}
	vector<pii> pnts;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		pnts.pb({x,y});
	}
	long double distx = 0;
	do{
		for(int i=1;i<n;i++){
			distx += dist(pnts[v[i]]._1,pnts[v[i]]._2,pnts[v[i-1]]._1,pnts[v[i-1]]._2);
		}
	}while(next_permutation(all(v)));
	cout<<fixed<<setprecision(10)<<(distx/fact(n));
	return 0;
}
//.........

Measured memory_bytes: 888
#include <stdio.h>
typedef struct ver{
  int e[101];
  int se;
  int color;
} ver;
  
int n,u;
int time;
int d[101];
int f[101];
ver g[101];

void visit(int u){
  int v,w;
  g[u].color=1;
  d[u] = ++time;
  for(v=1;v<=g[u].se;v++){
    w=g[u].e[v];
    if(g[w].color == 0){
      visit(w);
    }
  }
  g[u].color = 2;
  f[u] = ++time;
}

void dfs(){
  int u;
  for(u=1;u<=n;u++){
    g[u].color = 0;
  }
  time = 0;
  for(u=1;u<=n;u++){
    if(g[u].color==0){
      visit(u);
    }
  }
}




int main(){
  int i,j,k,v;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    g[u].se=k;
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      g[u].e[j]=v;
    }
  }

  dfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

void big(){
  if(l > 20){
    l = 1;
    m++;
  }
}

void small(){
  if(l > 19){
    l = 1;
    m++;
  }
}

void check(){
  if(m > 10){
    m = 1;
    n++;
  }
}

int main(){
  int p;
  cin >> p;
  while(p--){
    ll ans = 0;
    cin >> n >> m >> l;
    while(1){
      if(n == 1000 && m == 1 && l == 1)break;
      // cout << n << " " << m << " " << l << endl;
      ans++;
      l++;
      if(n % 3 == 0)big();
      else{
        if(m % 2)big();
        else small();
      }
      check();
    }
    print(ans);
  }
  return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int n;
double p[3000],dp[3000][3000]={0};
int main(){
    cin>>n;
    rep(i,n) cin>>p[i];
    dp[0][0]=1;
    rep(i,n)rep(j,i+2) dp[i+1][j]=dp[i][j]*(1-p[i])+dp[i][j-1]*p[i];
    double ans=0;
    rep(i,(n+1)/2) ans+=dp[n][n-i];
    cout<<setprecision(10)<<ans<<"\n";
}

Measured memory_bytes: 68864
#include<bits/stdc++.h>
using namespace std;
int a;
int main()
{
    int N,V[20],C[20];
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>V[i];

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

    }
    
    for(int k=0;k<N;++k)
    {
        if(V[k]>C[k]){
        a+=V[k]-C[k];
    }else a+=0;
    }
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>

using namespace std;

static const int N = 10000;

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


int main()
{
    int n, sum = 0;
    int A[N];
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        if(isPrime(A[i]))
            sum++;
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 2680
# include <bits/stdc++.h>
# define rr
const int N=100010,INF=0x3f3f3f3f;
struct Edge{
	int to,next;
}edge[N<<1];
int head[N],sum;
int h[N];
int ans;
int n,m;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
inline void add(int x,int y){
	edge[++sum].to=y;
	edge[sum].next=head[x];
	head[x]=sum;
	return;
}
int main(void){
	n=read(),m=read();
	for(rr int i=1;i<=n;++i){
		h[i]=read();
	}
	for(rr int i=1;i<=m;++i){
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	for(rr int i=1;i<=n;++i){
		if(!head[i]){
			++ans;
			continue;
		}
		for(rr int j=head[i];j;j=edge[j].next){
			if(h[edge[j].to]>=h[i]){
				goto End;
			}
		}
		++ans;
		End:;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 6084
#include<stdio.h>

  int main(void)
  {
   int h,a,n;
   scanf("%d%d",&h,&a);
   n=h/a;
   if(h%a>0) n++;
   //n=(h+a-1)//a;
   printf("%d\n",n);
   return 0;
   }




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int ng[100010];
ll dp[100010];

int main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int a;
        cin>>a;
        ng[a]=1;
    }

    dp[0]=1;
    rep(i,n){
        if(ng[i+1]) continue;
        dp[i+1]=(dp[i+1]+dp[i])%MOD;
        if(i-1>=0) dp[i+1]=(dp[i+1]+dp[i-1])%MOD;
    }
    
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4800
#include <stdio.h>

int main(void)
{
	char toe[10];
	int i;
	int flag;
	
	while(scanf("%s", toe) != EOF) {
		flag = 0;
		
		for(i = 0; i <= 9; i += 3){
			if(toe[i] == toe[i + 1] && toe [i + 1] == toe[i + 2]) {
				if(toe[i] == 'o'){
					printf("o\n");
					flag = 1;
				}
				else if(toe[i] == 'x'){
					printf("x\n");
					flag = 1;
				}
			}
		}
		
		if (flag != 1){
			for(i = 0; i <= 2; i++){
				if(toe[i] == toe[i + 3] && toe [i + 3] == toe[i + 6]) {
					if(toe[i] == 'o'){
						printf("o\n");
						flag = 1;
					}
					else if(toe[i] == 'x'){
						printf("x\n");
						flag = 1;
					}
				}
			}
		}
			
			if(flag != 1){
				if(toe[0] == toe[4] && toe[4] == toe[8]){
					if(toe[4] == 'o'){
						printf("o\n");
						flag = 1;
					}
					else if(toe[4] == 'x'){
						printf("x\n");
						flag = 1;
					}
				}
				else if(toe[2] == toe[4] && toe[4] == toe[6]){
					if(toe[4] == 'o'){
						printf("o\n");
						flag = 1;
					}
					else if(toe[4] == 'x'){
						printf("x\n");
						flag = 1;
					}
				}
			}
		
		if(flag != 1){
			printf("d\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0