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

using namespace std;

class UnionFindTree {
private:
    vector<int32_t> parent, rank;

    int32_t find(int32_t x) {
        if (parent[x] == x) {
            return x;
        } else {
            int32_t p = find(parent[x]);
            parent[x] = p;
            return p;
        }
    }

public:
    UnionFindTree(int32_t n) {
        parent.resize(n);
        rank.resize(n);

        for (int32_t i = 0; i < n; i++) {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    void unite(int32_t x, int32_t y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
        } else {
            parent[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

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

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

    UnionFindTree uf(n);
    priority_queue<tuple<int32_t, int32_t, int32_t>, vector<tuple<int32_t, int32_t, int32_t>>, greater<tuple<int32_t, int32_t, int32_t>>> E;

    for (int32_t i = 0; i < n; i++) {
        for (int32_t j = 0; j < n; j++) {
            int32_t w;
            cin >> w;

            if (w > -1) {
                E.push(make_tuple(w, i, j));
            }
        }
    }

    int32_t sum = 0;
    while (!E.empty()) {
        int32_t w, u, v;
        tie(w, u, v) = E.top();
        E.pop();
        if (!uf.same(u, v)) {
            sum += w;
            uf.unite(u, v);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3200
def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in xrange(N-1,0,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag += 1
                count += 1
    return A, count

def main():
    N = int(raw_input())
    A = map(int, raw_input().split())
    new_A, count = bubbleSort(A, N)
    print ' '.join(map(str,new_A))
    print count

if __name__ == "__main__":
    main()

Measured memory_bytes: 6468
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a-c)/(b+c) << endl;
/////////////////////////////////////////////
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n, vector<int>(0));
    vector<vector<int>> y(n, vector<int>(0));
    rep(i, n) {
        cin >> a.at(i);
        rep(j, a.at(i)) {
            int tmp1, tmp2;
            cin >> tmp1;
            tmp1--;
            x.at(i).push_back(tmp1);
            cin >> tmp2;
            y.at(i).push_back(tmp2);
        }
    }

    int ans = 0;
    for (int bits = 0; bits < (1 << n); bits++) {  // bit pattern
        vector<int> pattern;
        int num = 0;
        for (int i = 0; i < n; i++) {
            int mask = 1 << i;
            if (bits & mask) {  // i番目のbitが立っていれば加算する
                pattern.push_back(1);
                num++;
            } else {
                pattern.push_back(0);
            }
        }

        bool isOk = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < a.at(i); j++) {
                if (pattern.at(i) && pattern.at(x.at(i).at(j)) != y.at(i).at(j)) isOk = false;
            }
        }

        if (isOk) ans = max(ans, num);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
	int i,total,x,y;
	int idou[10];
	total=0;
	for(i=1;i<=4;i++){
		scanf("%d",&idou[i-1]);
		total+=idou[i-1];
	}
	x=total/60;y=total-x*60;
	printf("%d\n",x);
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using P = pair<int64_t,int64_t>;

struct edge{
  int64_t to;
  int64_t cost;
};

const int64_t MOD = 1e9+7;
const int64_t MAX_N = 100010;

P dp[MAX_N];
bool seen[MAX_N];

P dfs(vector<vector<edge>> &G, int64_t s, int64_t p){
  if(seen[s]){
    return dp[s];
  }
  else{
    int64_t x = 1; //black
    int64_t y = 1; //white
    for(int i=0; i<G[s].size(); i++){
      edge t = G[s][i];
      if(t.to == p){
        continue;
      }
      P d = dfs(G,t.to,s);
      x *= d.second;
      y *= d.first + d.second;
      x %= MOD;
      y %= MOD;
    }
    P q = {x,y};
    dp[s] = q;
    seen[s] = true;
    return dp[s];
  }
}
      

int main(){
  int N;
  cin >> N;
  vector<vector<edge>> G(N,vector<edge>(0));
  for(int i=0; i<N-1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge add = {a,0};
    G[b].push_back(add);
    add = {b,0};
    G[a].push_back(add);
  }
  
  for(int i=0; i<MAX_N; i++){
    seen[i] = false;
  }
  P ans = dfs(G,0,-1);
  cout << (ans.first + ans.second) % MOD << endl;
}




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

class Calc {
  private:
    string str;
    vector<char> p;
    string::iterator it;

  public:
    Calc (string str, vector<char> p) {
        this->str = str;
        this->p   = p;
        it = this->str.begin();
    }

    ll get_val(ll a, char op, ll b)
    {
        switch (op) {
            case '*':
                return a * b;
            case '+':
                return a + b;
            case '-':
                return a - b;                
        }
    }

    ll f0(int pt)
    {
        ll res = 0;
        if (*it == '(') {
            ++it;
            if (pt == 0) {
                res = f3(0);
            } else if (pt <= 2) {
                res = f2(pt);   
            } else {
                res = f1(3);
            }
            ++it;
        } else {
            while (isdigit(*it)) {
                res *= 10LL;
                res += (ll)(*it - '0');
                ++it;
            }
        }
        return res;
    }

    ll f1(int pt)
    {
        ll res = f0(pt);
        while (*it == p[0] ||
               (pt >= 2 && *it == p[1]) ||
               (pt >= 3 && *it == p[2])) {
            
            if (*it == p[0]) {
                ++it;            
                res = get_val(res, p[0], f0(pt));
            } else if (pt >= 2 && *it == p[1]) {
                ++it;
                res = get_val(res, p[1], f0(pt));
            } else if (pt >= 3 && *it == p[2]) {
                ++it;
                res = get_val(res, p[2], f0(pt));
            }            
        }
        return res;
    }

    ll f2(int pt)
    {
        ll res = f1(pt);
        if (pt == 0) {
            while (*it == p[1]) {
                ++it;
                res = get_val(res, p[1], f1(0));
            }
        } else if (pt == 1) {
            while (*it == p[1] || *it == p[2]) {
                if (*it == p[1]) {
                    ++it;
                    res = get_val(res, p[1], f1(1));                
                } else {                               
                    ++it;
                    res = get_val(res, p[2], f1(1));                
                }
            }
        } else if (pt == 2) {
            while (*it == p[2]) {
                ++it;
                res = get_val(res, p[2], f1(2));                
            }
        }
        return res;
    }

    ll f3(int pt)
    {
        ll res = f2(0);
        while (*it == p[2]) {
            ++it;
            res = get_val(res, p[2], f2(0));
        }
        return res;
    }
};

int main()
{
    string str;
    cin >> str;      
    vector<char> p = {'*', '+', '-'};
    ll res = LLONG_MIN;    
    do {
        for (int i = 0; i < 4; i++) {
            Calc  c(str, p);
            ll r = -1;
            if (i == 0) {
                r = c.f3(0);
            } else if (i <= 2) {
                r = c.f2(i);
            } else {
                r = c.f1(3);
            }
            res = max(res, r);
        }
    } while (next_permutation(p.begin(), p.end()));
    cout << res << endl;    
    return 0;
}

Measured memory_bytes: 3240
import collections
N = int(input())
A = list(map(int, input().split()))
count = collections.defaultdict(int)
currSum = 0
for a in A:
  count[a] += 1
  currSum += a
Q = int(input())
for _ in range(Q):
  B, C = map(int, input().split())
  currSum += (count[B] * (C - B))
  count[C] += count[B]
  count[B] = 0
  print(currSum)

Measured memory_bytes: 23852
#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 dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int dp[1002][1<<12];

int main(){
    std::ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cost(m);
    vector<int> open_set(m);
    for(int i=0;i<m;++i)
    {
        cin >> cost[i];
        int b, tmp;
        cin >> b;
        for(int j=0;j<b;++j)
        {
            cin >> tmp;
            open_set[i] |= 1 << (tmp-1);
        }
    }
    
    for(int i=0;i<m+1;++i)
        for(int j=0;j<(1<<12);++j)
            if(i==0 && j ==0)
            {
                dp[i][j] = 0;
            } else {
                dp[i][j] = (1ll << 30) - 1;
            }

    for(int i=1;i<=m;++i)
    {
        for(int j=0;j<(1<<12);++j)
        {
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            dp[i][j|open_set[i-1]] = min(dp[i][j|open_set[i-1]], dp[i-1][j] + cost[i-1]);
        }
    }

    if(dp[m][(1<<n)-1] == (1ll<<30) - 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << dp[m][(1<<n)-1] << endl;
    }
}

Measured memory_bytes: 16256
// c++ -std=c++14 atcoder.cpp
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int k;
    cin >> k;
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
}


Measured memory_bytes: 256
Imports System
 
Public Class Test
	Public Shared Sub Main()
	Dim n As Integer
        Dim TT As String
        Dim VV As String
        n = Console.ReadLine()
        TT = Console.ReadLine()
        VV = Console.ReadLine()
        Dim TTT As String() = TT.Split(" "c)
        Dim VVV As String() = VV.Split(" "c)
        Dim v(n) As Integer
        Dim t(n) As Integer
        Dim i As Integer = 1
        For Each vk As String In VVV
            v(i) = vk
            i += 1
        Next vk
        i = 1
        t(0) = 0
        For Each tk As String In TTT
            t(i) = tk + t(i - 1)
            i += 1
        Next tk
        v(0) = 0
 
        Dim bv As Single = 0
        Dim av As Single = 0
        Dim distance As Single = 0
        For j As Single = 0 To t(n) Step 0.5
            bv = av
            av = j
            For k As Integer = 1 To n
                If (velo(j, t(k - 1), t(k), v(k)) < av) Then
                    av = velo(j, t(k - 1), t(k), v(k))
                End If
            Next
            If t(n) - j < av Then
                av = t(n) - j
            End If
            distance += 0.25 * (av + bv)
        Next
        Console.WriteLine(math.round(distance*100)/100)
	End Sub
   Public Shared Function velo(time As Single, a As Single, b As Single, ve As Integer) As Single
        If (time < a) Then
            Return -time + a + ve
        ElseIf (time > b) Then
            Return time + ve - b
        Else
            Return ve
        End If
    End Function
End Class

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

using namespace std;

#define LCM(a,b)                (a / __gcd(a,b) ) *b
#define GCD(a,b)                __gcd(a,b)

#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define LL                      long long
#define ULL                     unsigned long long
#define pb                      push_back
#define tcase                   cout<<"Case "<<C++<<": ";
#define all(a)                  a.begin(),a.end()
#define Unique(a)               sort(all(a)),a.erase(unique(all(a)),a.end
#define ABS(x)                  ((x)<0?-(x):(x))
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(a,min(b,min(c,d)))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(a,max(b,max(c,d)))
#define PI                      acos(-1.0)
#define ff                      first
#define ss                      second
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define FastRead                ios_base::sync_with_stdio(0);cin.tie(NULL);
#define FOR(x, l, r)            for (LL x = l; x<=r; ++x)
#define REP(x,r)               for (LL x = 0; x <r; ++x)
#define NN                      cout<<"\n";
#define NNN                     cout<<"\n------------------------------\n";

//***********************************************************************//
//                      SHAHED AHMED, CSE'15, IUT                        //
//***********************************************************************//


int main()
{
        int n;
        cin>>n;
        vector<int> v;
        int x;
        for(int i=0;i<n;i++)
        {
               cin>>x;
               v.pb(x);
        }

        int cont =0;
        int ans=0;
        for(int i=0;i<v.size();i++)
        {
                if(i==0)
                {
                        cont = 1;
                }
                else if(v[i]!=v[i-1])
                {
                        ans+=cont/2;
                        cont = 1;
                }
                else
                {
                        cont++;
                }
        }
        ans+=cont/2;

        cout<<ans;
}





Measured memory_bytes: 256
n=gets.to_i
a=gets.chomp.split("")
b=gets.chomp.split("")
c=gets.chomp.split("")
cnt = 0
for i in 0..n-1
	if a[i] != b[i] && a[i] != c[i] && b[i] != c[i] then
		cnt += 2
	elsif a[i] != b[i] || a[i] != c[i] || b[i] != c[i] then
		cnt +=1
	end
end
puts cnt

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

bool isPrime(ll num) {
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  for (long long int i = 3; i*i <= num; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}

int main() {
  int x;
  cin >> x;
  
  int ans = x;
  while (!isPrime(ans))
    ans++;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])

vector = []
for mi in range(m):
    vector.append(int(input()))

b = []
for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]

    print(sum)

Measured memory_bytes: 8032
/**
*    author:  boutarou
*    created: 11.07.2020 21:01:27
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) {
        if (i % 2 == 0 && a[i] % 2 == 1) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>

#define STRSIZE 1024
#define MAXELNUM 100
#define STRELNUMSIZE 4

/**　関数のプロトタイプ宣言 */

void StrToIntArray( char*, int*);
void InsertionSort(int, int*);
void DisplayElements(int* , int);

/**
*Function Name : Main
*Action : 
*
*/

int main(void)
{
    int elemNum = 0;  /** Number of elements*/
    char strElNum[STRELNUMSIZE] = { "\0" }; /** 並べ替える数字の数　*/

    char strSpecLine[STRSIZE] = { "\0" }; /**　ソート対象数列(文字列)　*/
    int SpecLine[MAXELNUM] = { 0 };  /**　ソート対象数列　*/

    std::cin.getline(strElNum, STRELNUMSIZE); /**　ソート対象要素数入力受付　*/
    elemNum = std::atoi(strElNum);

    std::cin.getline(strSpecLine, STRSIZE); /**　ソート対象数列入力受付(文字列)　*/

    StrToIntArray( strSpecLine, SpecLine); 

    InsertionSort(elemNum, SpecLine);

    return 0;
}


/**
*関数:StrToIntArray
*機能:文字列を整数の配列へ変換する
*
*/


void StrToIntArray( char strSpecLine[], int SpecLine[])
{
    int i = 0, j = 0, ElementCount = 0;

    char strNum[5];

    for (i = 0; i < STRSIZE; i++) 
    {
        
        if (strSpecLine[i] == '\0') /**改行文字に当たった時*/
        {
            strNum[j] = '\0'; /**一時配列の最後に終端文字を挿入*/
            SpecLine[ElementCount] = std::atoi(strNum); /**(最後の数字を)整数に変換*/

            return; 
        }
        else if (strSpecLine[i] == ' ') /**空白(区切り文字)に当たった時*/
        {
            strNum[j] = '\0'; /**一時配列の最後に終端文字を挿入*/
            SpecLine[ElementCount] = std::atoi(strNum); /**文字列StrNumを整数に変換*/

            j = 0;
            ElementCount++;
        }
        else
        {
            strNum[j] = strSpecLine[i];
            j++;
        }
    }
    return;
}

/**関数名:InsertionSort
*機能:挿入ソートを実行し、挿入ソートの各ステップごとに表示する
*/

void InsertionSort(int elemNum, int SpecLine[])
{
    int j = 0;

    DisplayElements(SpecLine, elemNum);

    /**挿入ソート実行&表示*/

    for (int i = 1; i < elemNum; i++) 
    {

        /**Executing insertion sort*/
        int key = SpecLine[i]; /**Setting initial Key Value*/
        j = i - 1;
        
        while (( j >= 0) && (SpecLine[j] > key) ) /**When Array[j] is larger than key value*/
        {
            SpecLine[j + 1] = SpecLine[j];  /**Array[j] -> Array[j+1]*/
            j--;
        }

        SpecLine[j+1] = key; /**Key値は整列済みの最後尾に入る*/

        /**挿入ソートの各ステップ表示*/
        DisplayElements(SpecLine, elemNum);
    }
    return;
}

void DisplayElements(int* SpecimenArray, int ElemNum)
{
    for (int i = 0; i < ElemNum; i++)
    {
        std::cout << SpecimenArray[i]; /**要素一つを表示*/

        if (i == ElemNum - 1)
        {
            std::cout << std::endl; /**全要素を表示したら改行*/

        }
        else
        {
            std::cout << " "; /**次に表示する要素が残っている場合は空白を挿入*/
        }
    }
}



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

using namespace std;
mt19937_64 rng(58);

/* O(sqrt(n))
   n =     100,000   cost ~  0.0sec, max prime =   1,299,709
   n =   1,000,000   cost ~  1.7sec, max prime =  15,485,867
   n =  10,000,000   cost ~ 46.1sec, max prime = 179,424,673, ram ~ 40MB
*/
void generate_primes(int n, vector<int> &primes) {
  primes = { 2, 3, 5 };
  n -= 3;
  auto is_prime = [](int t, vector<int> &primes) -> bool {
    for (auto p : primes) {
      if (p * p > t) break;
      if (t % p == 0) return false;
    }
    return true;
  };
  for (int six = 6; n > 0; six += 6) {
    if (is_prime(six + 1, primes)) primes.push_back(six + 1), n--;
    if (is_prime(six + 5, primes)) primes.push_back(six + 5), n--;
  }
}

/* return 2, 2, 2, 5, 7 for 2^3 * 5 * 7 */
vector<int> factorize(int x, vector<int> &primes) {
  vector<int> factors;
  int bound = x;
  for (auto p : primes) {
    if (x == 1 || p * p > bound) break;
    for (; x % p == 0; x /= p) factors.push_back(p);
  }
  if (x != 1) factors.push_back(x);
  return factors;
}

template<typename T>
vector<pair<T, int>> rle_compress(vector<T> list) {
  vector<pair<T, int>> r;
  for (auto e : list) {
    if (r.empty() || e != r.back().first) r.emplace_back(e , 1);
    else (r.end() - 1)->second++;
  }
  return r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    vector<int> primes;
    generate_primes(100000, primes);
    int n;
    cin >> n;
    vector<int> a(n); for (auto &ai : a) cin >> ai;
    map<int, int> count;
    vector<vector<pair<int, int>>> factors(n);
    for (int i = 0; i < n; i++) {
        factors[i] = rle_compress(factorize(a[i], primes));
        for (auto f : factors[i]) {
            count[f.first] += f.second;
        }
    }
    bool pairwise = true;

    for (int i = 0; i < n; i++) {
        for (auto f : factors[i]) {
            if (count[f.first] != f.second) {
                pairwise = false;
                break;
            }
        }
    }

    if (pairwise) {
        cout << "pairwise coprime\n";
    } else {
        bool coprime = true;
        map<int, int> mcount;
        for (int i = 0; i < n; i++) {
            for (auto f : factors[i]) {
                mcount[f.first]++;
            }
        }
        for (auto p : mcount) {
            if (p.second == n) {
                coprime = false;
                break;
            }
        }
        if (coprime) {
            cout << "setwise coprime\n";
        } else {
            cout << "not coprime\n";
        }
    }
}

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

using namespace std;
using ll = long long;

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

int main() {
  int a, b;
  cin >> a >> b;

  int ans = max(a, b);
  if (a > b)
    --a;
  else
    --b;
  ans += max(a, b);
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, q;
  cin >> n;
  ll sum = 0;
  vector<ll> num(110000, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    sum += a;
    num[a]++;
  }

  cin >> q;
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    sum += (c - b) * num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 4060
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

vector<int> g[100000];
int c[100000];
bool used[100000];
bool nuee;
int d;
void dfs(int x){
  if(nuee) return;
  used[x]=1;
  vector<int> v;
  for(auto y:g[x]){
    if(used[y]) continue;
    dfs(y);
    if(nuee) return;
    v.push_back(c[y]+1);
  }
  if(v.empty()) return;
  if(v.size()==1){
    if(v[0]>d) nuee=1;
    c[x]=v[0];
    return;
  }
  if(v.size()%2==0) v.push_back(0);
  sort(v.begin(), v.end());
  int m=v.size();
  bool ok0=0;
  for(int i=0; i<m; i++){
    int c1=0, c2=m-1;
    bool ok=1;
    for(int j=0; j<m/2; j++){
      if(c1==i) c1++;
      if(c2==i) c2--;
      if(v[c1]+v[c2]>d){
        ok=0;
        break;
      }
      c1++; c2--;
    }
    if(ok){
      ok0=1;
      c[x]=v[i];
      break;
    }
  }
  if(!ok0){
    nuee=1;
  }
}

int main()
{
	int n; cin>>n;
  for(int i=0; i<n-1; i++){
    int a, b;
    cin>>a>>b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ct=0;
  int v0;
  for(int i=0; i<n; i++){
    if(g[i].size()%2) ct++;
    if(g[i].size()==1) v0=i;
  }
  cout<<ct/2<<" ";
  int d1=1, d2=2e5;
  while(d1!=d2){
    d=(d1+d2)/2;
    fill(c, c+n, 0);
    fill(used, used+n, 0);
    nuee=0;
    dfs(v0);
    if(nuee) d1=d+1;
    else d2=d;
  }
	cout<<d1<<endl;
	return 0;
}

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

int main(){
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>> root(N);
	int cost = 0;
	for (int i = 0;i < N;++i) {
		cin >> root[i].first >> root[i].second;
		if (root[i].second <= T) {
			if (cost == 0)cost = root[i].first;
			else if (cost > root[i].first)cost = root[i].first;
		}
	}
	if (cost == 0)cout << "TLE" << endl;
	else cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N;
    cin >> N;
    vector<ll> a(N);
    loop(i, N) cin >> a[i];
    ll maxx = 0;
    loop(i, N) maxx = max(maxx, abs(a[i]));
    ll mind;
    loop(i, N)
    {
        if (abs(a[i]) == maxx)
        {
            mind = i;
            break;
        }
    }
    vector<ll> X, Y;
    loop(i, N)
    {
        if (i == mind)
            continue;
        X.push_back(mind + 1);
        Y.push_back(i + 1);
    }
    if (a[mind] >= 0)
    {
        loop(i, N - 1)
        {
            X.push_back(i + 1);
            Y.push_back(i + 2);
        }
    }
    else
    {
        for (ll i = N - 1; i > 0; i--)
        {
            X.push_back(i + 1);
            Y.push_back(i);
        }
    }
    putout(2 * (N - 1));
    loop(i, 2 * (N - 1))
    {
        cout << X[i] << " " << Y[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
def main():
    S = input()
    counter = dict()

    for c in S:
        if c in  counter:
            counter[c] += 1
        else:
            counter[c] = 1

    if len(counter) == 2:
        for c in counter.keys():
            if counter[c] != 2:
                print("No")
                break
        else:
            print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;
using ll = long long int;
using dd = long double;
const dd PI = 3.1415926535;

dd f(dd A, dd B, dd deg) {
  if (deg == 0) {
    return 0.0;
  }

  if (B / tan(deg) > A) {
    dd full = A * A * B;
    return full - A * A * A * tan(deg) / 2.0;
  } else {
    dd water = A * B * B / tan(deg) / 2.0;
    return water;
  }
}

int main() {
  dd A, B, X;
  cin >> A >> B >> X;


  dd ans = 0.0;
  dd l = 0.0;
  dd r = 90.0;

  while (abs(l - r) > 1e-9) {
    dd mid = (l + r) / 2.0;
    dd rad = PI * mid / 180.0;
    if (f(A, B, rad) <= X){
      r = mid;
    } else{
      l = mid;
    }
  }
  ans = l;
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;


int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A.begin(),A.end());
  int b = A[N/2];
  ll sum=0;
  for(int i=0; i<N; i++){
    sum += abs(A[i]-b);
  }
  cout << sum << endl;
  return 0;
}


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

int main(){
  int N, K ;
  cin >> N >> K;
  
  vector<int>a(N);
  rep(i,N) cin >> a[i];
  sort(a.begin(),a.end());
  
  ll sum = 0;
  rep(i,N-K) sum += a[i];
  
  cout << sum << endl;
    
}
  

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

#define llint long long int
using namespace std;

int main(){
  int n;
  cin >> n;
  llint a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  if(n > 1){
    llint left[n+1] = {}, right[n+1] = {};
    for(int i = 0; i < n; i++){
      left[i+1] = __gcd(left[i], a[i]);
      right[n-i-1] = __gcd(right[n-i], a[n-i-1]);
    }
    llint ans = 0;
    for(int i = 0; i < n; i++){
      ans = max(ans, __gcd(left[i], right[i+1]));
    }
    cout << ans << endl;
  }
  else
    cout << a[0];
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

int N;
vector<vector<int>> abc; 
vector<vector<int>> dp;

ll req(int i, int j){
    if(dp[i][j] != -1) return dp[i][j];
    
    ll res = -1;
    for(int k = 0; k < 3; k++){
        if(j==k) continue;
        res = max(res, req(i-1, k) + abc[i][j]);
    }
    
    return dp[i][j] = res;
}

int main(void){
    cin >> N;
    abc.resize(N, vector<int>(3)); 
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            cin >> abc[i][j];
        }
    }
    
    dp.resize(N,vector<int>(3, -1));
    dp[0][0] = abc[0][0];
    dp[0][1] = abc[0][1];
    dp[0][2] = abc[0][2];
    
    ll ans = 0;
    for(int i = 0; i < 3; i++){
        ans = max(ans, req(N-1, i));
    }
    
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < 3; j++){
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << "\n";
    // }
    cout << ans << "\n";
}


Measured memory_bytes: 18944
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: chars,
    }
    let N = S.len();
    let mut a = 0;
    let mut z = 0;
    for i in 0..N{
        if S[i]=='A'{
            a = i;
            break;
        }
    }
    for i in 0..N{
        if S[N-1-i]=='Z'{
            z = N-1-i;
            break
        }
    }
    println!("{}",z-a+1);
}

Measured memory_bytes: 4352
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);
  const C = input[1].map(Number);

  let score = 0;

  const T: number[] = [];
  const L = Array(26).fill(0);

  for (let d = 0; d < D; d++) {
    const S = input[d + 2].map(Number);

    let max = Number.MIN_SAFE_INTEGER;
    let index = 0;

    S.forEach((s, i) => {
      const temp =
        score +
        s -
        C.reduce((sum, c, j) => (j === i ? sum : sum + c * (d + 1 - L[j])), 0);

      if (temp > max) {
        max = temp;
        index = i;
      }
    });

    T.push(index + 1);
    L[d] = index;
  }

  return T.join("\n");
};

console.log(main(read()));


Measured memory_bytes: 33992
n = int(input())

from math import sqrt
def dist(x1, y1, x2, y2):
    return sqrt((x1-x2)**2 + (y1-y2)**2)
xx = []
yy = []
for i in range(n):
    x, y = map(int, input().split())
    xx += [x]
    yy += [y]

dists = [dist(xx[i], yy[i], xx[j], yy[j]) for i in range(n) for j in range(i+1,n)]      
print((n-1) * sum(dists) / len(dists))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

class UnionFind {
    struct UFNode {
        int par;
        int rank;
        int num;
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
            nodes[i].num = 1;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
            nodes[y].num += nodes[x].num;
        } else {
            nodes[y].par = x;
            nodes[x].num += nodes[y].num;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    int size(int x) {
        return nodes[root(x)].num;
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    LL n,m,k;
    cin >> n >> m >> k;
    vector<set<int>> bs(n);
    UnionFind uf(n);
    int a,b;
    VP ps(m);
    REP(i,0,m) {
        cin >> a >> b;
        --a; --b;
        uf.unite(a,b);
        ps[i] = MP(a,b);
    }
    VI ans(n);
    REP(i,0,n) ans[i] = uf.size(i) - 1;

    REP(i,0,m) {
        int a = ps[i].first, b = ps[i].second;
        if (uf.same(a,b)) {
            ans[a]--;
            ans[b]--;
        }
    }

    REP(i,0,k) {
        cin >> a >> b;
        --a; --b;
        if (uf.same(a,b)) {
            ans[a]--;
            ans[b]--;
        }
    }
    REP(i,0,n) cout << ans[i] << " ";
    cout << endl;
}

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

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

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

  string s, t = "AGCT";
  cin >> s;

  ll ans = 0, res = 0, flg;
  REP(i, s.size()){
    flg = 1;
    REP(j, 4){
      if(s[i] == t[j]){
        res++;
        flg = 0;
        break;
      }
    }
    if(flg){
      res = 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while (true){
            String str = sc.next();
            for (int i = 0; i < str.length(); i++){
                if (Character.isUpperCase(str.charAt(i))){
                    System.out.print(Character.toLowerCase(str.charAt(i)));
                } else if (Character.isLowerCase(str.charAt(i))){
                    System.out.print(Character.toUpperCase(str.charAt(i)));
                } else {
                    System.out.print(str.charAt(i));
                }
            }
            if (sc.hasNext())
                System.out.print(" ");
            else
                break;
        }
        System.out.println();
    }
}



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

using namespace std;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
const int mod = 1e9 + 7;
const int maxn = 1e6 + 50;
#define lowbit(x) ((x)&(-x))

inline int mul( int x , int y ){
	return 1LL * x * y % mod;
}

inline void upd( int & x , int y ){
	x += y;
	if( x >= mod )
		x -= mod;
}

int power( int x , int y ){
	int ret = 1;
	while( y ){
		if( y & 1 )
			ret = mul( ret , x );
		y >>= 1;
		x = mul( x , x );
	}
	return ret;
}

int f[maxn] , tree[maxn] , n;

inline void Modify( int x , int y ){
	while( x <= n ){
		upd( tree[x] , y );
		x += lowbit( x );
	}
}

int prefix( int x ){
	int ret = 0;
	while( x ){
		upd( ret , tree[x] ) ;
		x -= lowbit( x );
	}
	return ret;
}


int main( int argc , char * argv[] ){
	cin >> n ;
	if( n == 1 ){
		puts( "1" );
		return 0;
	}
	f[0] = 1 , f[1] = n;
	Modify( 1 , f[1] );
	for(int x = 2 ; x <= n ; ++ x){
		upd( f[x] , f[x - 1] + n );
		upd( f[x] , mul( n - 2 , n - 1 ) );
		if( x == 3 )
			upd( f[x] , n - x + 1 );
		else if( x == 2 )
			upd( f[x] , n - 2 );
		else{
			upd( f[x] , n - x + 1 );
			upd( f[x] , prefix( x - 3 ) );
		}
		Modify( x , f[x] );
	}
	cout << f[n] << endl;
    return 0;
}

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

int main() {
  int N, tall = 0;
  int64_t sum = 0;
  cin >> N;
  vector<int64_t> A(N);
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) > tall) {
      tall = A.at(i);
//      cout << "tall changed:" << tall << endl;
    }
    else {
      sum += (tall - A.at(i));
//      cout << "sum changed:" << sum << endl;
    }
  }
  // 結果出力
  cout << sum << endl;
  return 0;
}

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

int main()
{
	using namespace std;
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		auto square = [](unsigned x) {return x * x; };

		vector<unsigned> sides(3, 0);
		cin >> sides[0] >> sides[1] >> sides[2];
		sort(sides.begin(), sides.end());


		if (square(sides[0]) + square(sides[1]) == square(sides[2]))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}


Measured memory_bytes: 3024
A, B = map(int, input().split())
S = input()

ans = 'Yes'
for i, s in enumerate(S):
    if i == A:
        if s != '-':
            ans = 'No'
            break
    else:
        if s not in '0123456789':
            ans = 'No'
            break

print(ans)


Measured memory_bytes: 2940
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n;
vector<vector<int>> G;
// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離, 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex)
{
    // 距離と終点を更新
    if (dist > maxDist)
    {
        maxDist = dist;
        maxVertex = current;
    }

    for (auto to : G[current])
    {
        // 逆流を防ぐ
        if (to == from)
            continue;
        treeDFS(current, to, dist + 1, maxDist, maxVertex);
    }
}

int getTreeDiameter()
{
    //ある点からDFSして最も遠かった点から2回目のDFSする
    //二回目の始点と最も遠い点が直径になる
    int start = 0, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    return maxDist;
    //printf("start: %d, end: %d, diameter: %d\n", start, end, maxDist);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    G.resize(n);
    if (n == 1)
    {
        cout << "First"
             << "\n";
        return 0;
    }
    for (int i = 0; i < n-1; i++)
    {
        int temp, temp1;
        cin >> temp >> temp1;
        temp--;
        temp1--;
        G[temp].push_back(temp1);
        G[temp1].push_back(temp);
    }
    int dist = getTreeDiameter();
    vector<bool> dp(dist + 1, false);//先手基準
    dp[1] = false;
    dp[2] = true;
    for (int i = 3; i <= dist; i++)
    {
        if(dp[i-1]&&dp[i-2]){
            dp[i]=false;//相手に勝ちを譲らざる追えない時負け
        }
        else{
            dp[i]=true;
        }
    }
    if(dp[dist]){
        cout<<"First"<<"\n";
    }
    else{
        cout<<"Second"<<"\n";
    }
}


Measured memory_bytes: 26880
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int a[5],k;
    for(int i=0;i<5;i++)
    scanf("%d",&a[i]);
    scanf("%d",&k);
    sort(a,a+5);
    if(a[4]-a[0]>k)
        cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

ll A[MAXN];
ll cal[50];
char S[MAXN];

ll solve(ll k,int digit,int n)
{
    if(!digit){
        if(k==0)return (cal[digit]);
        else return max(n-cal[digit],cal[digit]);
    }

    if((1LL<<digit)&k){
        ll res = (((ll)n-cal[digit])<<digit)+solve((k^(1LL<<digit)),digit-1,n);
        ll sum = (cal[digit]<<digit);
        for(int j=digit-1;j>=0;j--)
            sum+=((max(n-cal[j],cal[j]))<<j);
        res = max(res,sum);
        return res;
    }
    else return ((cal[digit]<<digit))+solve(k,digit-1,n);
}

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;

    for(int i=0;i<n;i++)
        cin>>A[i];

    for(int i=0;i<40;i++){
        for(int j=0;j<n;j++)
            if(A[j]&(1LL<<i))cal[i]++;
    }

    ll res = solve(k,39,n);

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 1024
import itertools

n = int(input())
pos = tuple(tuple(int(i) for i in input().split()) for _ in range(n))

def distance(x, y):
    return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5

totals = []
for path in itertools.permutations(pos, n):
    d = 0
    for i in range(len(path)-1):
        d += distance(path[i], path[i+1])
    totals.append(d)

print(sum(totals) / len(totals))

Measured memory_bytes: 42348
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,ans;

bool fn( ll x ){
    ll myAns = 0;
    while( x ) myAns++ , x/=10;
    return myAns&1;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(ll i=1; i<=n; i++) if( fn(i) ) ans++;
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x7fffffff
#define MAXN 100010
#define MOD 1000000007
#define int long long
using namespace std;
inline int read(){
	int ret=0,pos=1;char c=getchar();
	while(!isdigit(c) && c!='-' ) c=getchar();
	if(c=='-')	pos=-1,c=getchar();
	while(isdigit(c))ret=(ret<<3)+(ret<<1)+c-48,c=getchar();
	return pos*ret;
}
inline int fst_pow(int a,int b){
	int ret=1;
    for(;b;b>>=1,a=(a*a)%MOD)	if(b&1)	ret=a*ret%MOD;
    return ret;
}
int Inc(int a,int b) { return (a+= b)>=MOD?a-MOD:a; }
int Dec(int a,int b) { return (a-= b)<0?a+MOD:a; }
int n,m,a,b;
int Sum(int x){return Dec(fst_pow(2,x),1);}
int F(int x){
	int ans1=1,ans2=1;
	for(int i=1;i<=x;++i)	ans1=(ans1*i)%MOD;
	for(int i=n-x+1;i<=n;++i)	ans2=(ans2*i)%MOD;
	ans2=(ans2*fst_pow(ans1,MOD-2))%MOD;
	return ans2;
}
signed main(){
	n=read(),a=read(),b=read();
	cout<<Dec(Sum(n),Inc(F(a),F(b)))<<endl;
	return 0;
}

Measured memory_bytes: 256