akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    vector<int> v(N + 1);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        l--; 
        v[l]++;
        v[r]--;
    }

    REP(i, N) {
        v[i + 1] += v[i];
    }

    int ans = 0;
    REP(i, N) {
        if (v[i] == M) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)
half = a[0] / 2
sa = float("inf")
ans = 0
for i in a[1:]:
    if abs(half - i) < sa:
        ans = i
        sa = abs(half - i)

print(a[0], ans)

Measured memory_bytes: 14432
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;
using uint64 = unsigned long long;
using int128 = __int128_t;
using uint128 = __uint128_t;
using float64 = long double;

template <typename T = int>
struct Range {
  struct RangeIterator {
    T i, step;

    RangeIterator(T i, T step) : i{i}, step{step} {}

    T &operator*() { return i; }
    RangeIterator &operator++() {
      i += step;
      return *this;
    }
    bool operator!=(const RangeIterator &rhs) const {
      return (step > 0 && i < rhs.i) || (step < 0 && i > rhs.i);
    }
  };

  T start, stop, step;

  Range(T start, T stop, T step) : start{start}, stop{stop}, step{step} {}
  Range(T start, T stop) : Range(start, stop, 1) {}
  Range(T stop) : Range(0, stop, 1) {}

  RangeIterator begin() const { return RangeIterator{start, step}; }
  RangeIterator end() const { return RangeIterator{stop, step}; }
};

template <typename T>
inline void ChooseMax(T &a, const T &b) {
  a = std::max(a, b);
}

template <typename T>
inline void ChooseMin(T &a, const T &b) {
  a = std::min(a, b);
}

template <typename T>
std::ostream& operator<<(std::ostream& ostr, const std::vector<T>& vec) {
  ostr << "[";
  for (auto itr = vec.begin(); itr != vec.end(); itr++) {
    if (itr != vec.begin()) {
      ostr << ", ";
    }
    ostr << *itr;
  }
  ostr << "]";
  return ostr;
}

template <typename K, typename V>
std::ostream& operator<<(std::ostream& ostr, const std::map<K, V>& map) {
  ostr << "{";
  for (auto itr = map.begin(); itr != map.end(); itr++) {
    if (itr != map.begin()) {
      ostr << ", ";
    }
    ostr << itr->first << " => " << itr->second;
  }
  ostr << "}";
  return ostr;
}

template <typename T>
std::ostream& operator<<(std::ostream& ostr, const std::set<T>& set) {
  ostr << "{";
  for (auto itr = set.begin(); itr != set.end(); itr++) {
    if (itr != set.begin()) {
      ostr << ", ";
    }
    ostr << *itr;
  }
  ostr << "}";
  return ostr;
}

template <typename F, typename S>
std::ostream& operator<<(std::ostream& ostr, const std::pair<F, S>& pair) {
  ostr << "(" << pair.first << ", " << pair.second << ")";
  return ostr;
}

void SolveProblem() {
  int X, Y, Z;
  std::cin >> X >> Y >> Z;

  std::swap(X, Y);
  std::swap(X, Z);
  std::cout << X << " " << Y << " " << Z << std::endl;
}

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

  std::cout.setf(std::ios::fixed);
  std::cout.precision(10);

  SolveProblem();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll k,n;
 cin>>k>>n;
 vector<ll> a(2*n);
 for(ll i=0;i<n;i++){
  cin>>a[i];
 }
 for(ll i=0;i<n;i++) a[i+n] = a[i] + k;
 ll res = inf;
 for(ll i=0;i<n;i++) res = min( res , a[n-1+i] - a[i] );
 cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int n;
int dp[100005][3];
vector<int> v[3];
int calc(int idx, int actv) {
	if (idx == n)
		return 0;
	int &ret = dp[idx][actv];
	if (ret != -1)
		return ret;
	int cost = v[actv][idx];
	for (int i = 0; i < 3; ++i) {
		if (i == actv)
			continue;
		ret = max(ret, cost + calc(idx + 1, i));
	}
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n;
	for (int i = 0; i < 3; ++i)
		v[i].resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d%d%d", &v[0][i], &v[1][i], &v[2][i]);
	int ans = 0;
	for (int i = 0; i < 3; ++i) {
		int cost = v[i][0];
		for (int j = 0; j < 3; ++j) {
			if (i == j)
				continue;
			ans = max(ans, cost + calc(1, j));
		}
	}
	cout << ans << endl;

	return 0;
}

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

ll inf = 1e18;

struct unionfind{
    vector<int> parent;
    vector<int> rank;
    vector<int> size;
    vector<pair<ll, ll>> cost;
    
    unionfind (int N) {
        parent = vector<int>(N);
        iota(parent.begin(), parent.end(), 0);
        rank = vector<int>(N, 0);
        size = vector<int>(N, 1);
        cost = vector<pair<ll, ll>>(N, {inf, 0});
    }
    
    int root(int x) {
        if (parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }
    
    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 (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
            if (cost[x] > cost[y]) cost[x] = cost[y];
        }
        else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) rank[y] += 1;
            if (cost[y] > cost[x]) cost[y] = cost[x];
        }
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    if (N < 2*(N-M-1)) {
        cout << "Impossible" << endl;
        return 0;
    }
    if (N == M+1) {
        cout << 0 << endl;
        return 0;
    }
    unionfind uf(N);
    vector<pair<ll, int>> pcost(N);
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        uf.cost[i] = {a, i};
        pcost[i] = {a, i};
    }
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    
    vector<ll> connect1, connect2;
    vector<bool> use(N);
    int cnt = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (i == uf.root(i)) {
            use[uf.cost[i].second] = true;
            ans += uf.cost[i].first;
            cnt++;
        }
    }
    sort(pcost.begin(), pcost.end());
    int pos = 0;
    while (cnt < 2*(N-M-1)) {
        if (!use[pcost[pos].second]) {
            ans += pcost[pos].first;
            cnt++;
        }
        pos++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>

void swap(int*,int*);
int left(int);
int right(int);
int parent(int);
void maxHeapify(int *,int);
void buildMaxHeap(int *);

int length;

int main(){
  int i,n,A[500001];

  scanf("%d",&length);
  for(i=1;i<=length;i++) scanf("%d",&A[i]);
  
  buildMaxHeap(A);

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


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

int left(int a){
  return 2*a;
}

int right(int a){
  return 2*a+1;
}

int parent(int a){
  return a/2;
}



void maxHeapify(int *A,int i){
  int l,r,largest;
  l=left(i);
  r=right(i);
  if(l<=length && A[l]>A[i]) largest = l;
  else largest=i;

  if(r<=length && A[r]>A[largest]) largest = r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(A,largest);
  }
  
}


void buildMaxHeap(int *A){
  int i;
  for(i=length/2;i>=1;i--){
     maxHeapify(A,i);
  }
  
}




Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[100001],pref[100001];
int main(){
cin>>n;
for(ll k=1;k<=n;k++){
    cin>>a[k];
    pref[a[k]]++;
}
for(ll k=1;k<=1000;k++)
    pref[k]+=pref[k-1];
    ll ans=0;
for(int k=1;k<=n;k++){
  for(int i=k+1;i<=n;i++){
    int x=a[i];
    int y=a[k];
    int t=abs(x-y);
    int l=max(0,t),r=min(1000,x+y-1);
    int u=pref[r]-pref[l];
    ans+=u;
    if(l+1<=x && x<=x+y-1)
        ans--;
        if(l+1<=y && y<=x+y-1)
        ans--;
  }
}
cout<<ans/3;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ((a+b)%2 == 0) System.out.println((a+b)/2);
		else System.out.println((a+b)/2+1);
	}
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    set<string> se;
    string w;
    cin >> w;
    se.insert(w);
    for(ll i = 1; i < N; i++){
        string s;
        cin >> s;
        if(se.find(s) != se.end() || w[w.size() - 1] != s[0]){
            cout << "No\n";
            return 0;
        }
        w = s;
        se.insert(w);
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
deque<int>deq;
signed main() {
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == ' ') 
			continue;
		if ('0' <= s[i] && s[i] <= '9') {
			string h = "";
			int j = i;
			while (j < s.size() && '0' <= s[j] && s[j] <= '9') {
				h += s[j];
				j++;
			}
			deq.push_back(stoll(h));
			i = j - 1;
		}
		else {
			int y = deq.back();
			deq.pop_back();
			int x = deq.back();
			deq.pop_back();
			switch (s[i]) {
			case '+':deq.push_back(x + y); break;
			case '-':deq.push_back(x - y); break;
			case '*':deq.push_back(x * y); break;
			}
		}
	}
	cout << deq.front() << endl;
}


Measured memory_bytes: 3220
program scoring
    implicit none
    integer(8)::t1,t2,t_rate,t_max,diff!実行時間の計測関連
    integer(8)::D,C(26),last(26,365),last_sim(26,365),i,j,k,vmax,tbest,torigin
    integer(8)::drand,qrand!局所探索法の書き換え関連
    integer(8)::contests=26
    integer(8)::steps=0!ベンチマーク用
    integer(8),allocatable::S(:,:),T(:),V(:),Vorigin(:)
    !時間計測開始
    call system_clock(t1)

    !入力
    read*,D,C
    allocate(S(26,D))
    allocate(T(D))
    allocate(V(D))
    allocate(Vorigin(D))
    read*,S
    T=0
    V=0
    last=0
    last_sim=0

    !貪欲法による初期解の生成
    do i=1,D
        do j=1,26
            !得点の初期化
            if(i==1)V(i)=0
            if(i>1)V(i)=V(i-1)

            !lastの初期化
            if(i==1)last(:,i)=0
            if(i>1)last(:,i)=last(:,i-1)

            last(j,i)=i
            V(i)=V(i)+S(j,i)
            
            do k=1,26
                V(i)=V(i)-C(k)*(i-last(k,i))
            end do

            if(j==1)then
                vmax=V(i)
                tbest=j
            else if(V(i)>=vmax)then
                vmax=V(i)
                tbest=j
            end if
        end do
        if(i==1)last(:,i)=0
        if(i>1)last(:,i)=last(:,i-1)
        T(i)=tbest
        last(tbest,i)=i
    end do
    vmax=V(D)
    call system_clock(t2,t_rate,t_max)
    diff=t2-t1

    do
        if(diff>1990000000)exit
		steps=steps+1
        !乱数の生成
        drand=rnd_int(D)
        qrand=rnd_int(contests)

        last_sim(:,:)=last(:,:)
        Vorigin(:)=V(:)
        !drand日目に行うコンテストをqrandに変更する
        !last_simの書き換え
        torigin=T(drand)
        if(drand==1)then
            last_sim(T(drand),1)=0
            last_sim(qrand,1)=1
        else
            last_sim(T(drand),drand)=last(T(drand),drand-1)
            last_sim(qrand,drand)=drand
        end if
        !日付に対応するコンテストタイプの書き換え
        T(drand)=qrand

        !drand日目の得点の再計算
        if(drand==1)then
            V(drand)=0
        else
            V(drand)=V(drand-1)
        end if
        V(drand)=V(drand)+S(T(drand),drand)
        do i=1,26
            V(drand)=V(drand)-C(i)*(drand-last(i,drand))
        end do

        !drand+1日目以降の得点の再計算
        do i=drand+1,D
            last_sim(:,i)=last(:,i-1)
            V(i)=V(i-1)
            V(i)=V(i)+S(T(i),i)
            last(T(i),i)=i
            do j=1,26
                V(i)=V(i)-C(j)*(i-last(j,i))
            end do
        end do

        if(V(D)>vmax)then
            vmax=V(D)
            last(:,:)=last_sim
        else
            V(:)=Vorigin(:)
            T(drand)=torigin
        end if
        !時間計測
        call system_clock(t2,t_rate,t_max)
        diff=t2-t1
    end do
    !print*,diff/dble(t_rate),steps
    !答えの出力
    do i=1,D
        print'(i0)',T(i)
    end do
contains
function rnd_int(rnd_max)
    integer(8),intent(in)::rnd_max
    integer(8)::rnd_int
    real::rnd_real
    call random_number(rnd_real)
    rnd_int=mod(int(rnd_real*100000000),rnd_max)+1
    return
end function
end program scoring

Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    vector<vector<ll>> dp(n+1,vector<ll>(3));
    int sumM[n+1]; sumM[0]=0;
    rep(i,n){
        sumM[i+1]=sumM[i];
        if(s[i]=='M') sumM[i+1]++;
    }
    rep(cas,q){
        int k; cin >> k;
        dp[0][0]=dp[0][1]=dp[0][2]=0;
        rep(i,n){
            rep(j,3){
                dp[i+1][j]=dp[i][j];
            }
            if(i+1-k>=0){
                if(s[i+1-k]=='D'){
                    dp[i+1][0]--;
                    dp[i+1][1]-=(sumM[i+1]-sumM[i+1-k+1]);
                }
            }
            if(s[i]=='D') dp[i+1][0]++;
            if(s[i]=='M') dp[i+1][1]+=dp[i][0];
            if(s[i]=='C') dp[i+1][2]+=dp[i][1];
        }
        cout << dp[n][2] << endl;
    }
}


Measured memory_bytes: 62860
#include <stdio.h>
#include <limits.h>

#define MAX 1000
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int A[MAX] = {0};
int B[MAX] = {0};
int T[10000 + 1];
int n, s;

int partition(int A[], int p, int r) {
	int x, i, j, tmp;
	x = A[r];
	i = p - 1;

	for (j = p; j < r; ++j) {
		if (A[j] <= x) {
			++i;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i + 1;
}

void quicksort(int A[], int p, int r) {
	int q;
	if (p < r) {
		q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q+1, r);
	}
}

int solve() {
	int ans = 0;
	int i, cur, S, m, an, v;
	short V[MAX] = {0};

	for (i = 0; i < n; ++i) {
		B[i] = A[i];
		V[i] = 0;
	}
	quicksort(B, 0, n-1);
	/* for (i = 0; i < n; ++i) { */
	/* 	printf("%d ", B[i]); */
	/* } */
	//printf("\n");

	for (i = 0; i < n; ++i) T[B[i]] = i;
	for (i = 0; i < n; ++i) {
		if (V[i]) continue;
		cur = i;
		S = 0;
		m = INT_MAX;
		an = 0;
		while (1) {
			V[cur] = 1;
			an++;
			v = A[cur];
			m = MIN(m, v);
			S += v;
			cur = T[v];
			//	printf("i = %d, cur = %d, v = %d, S = %d, an = %d, ans = %d\n", i, cur, v, S, an, ans);
			if (V[cur]) break;
		}
		ans += MIN(S + (an - 2) * m, m + S + (an + 1) * s);
	}

	return ans;
}

int main(void) {
	int i;
	scanf("%d", &n);
	s = INT_MAX;
	
	for (i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
		if (s > A[i]) s = A[i];
	}

	printf("%d\n", solve());
	
	return 0;
}

Measured memory_bytes: 656
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.next());
		Set<String> set=new HashSet<>();
		for(int i=0;i<num;i++) {
			set.add(sc.next());
		}
		System.out.println(set.size());
	}

}


Measured memory_bytes: 76768
#include<bits/stdc++.h>
#define lli long long int
using namespace std;

lli n;
lli sum(lli i,vector<vector<lli> > &arr)
{
    lli val = 0;
    vector<lli> vec;
    for(lli j=0;j<n;j++)
    {
        if(i & (1<<j))
            vec.push_back(j);
    }
    //cout<<vec.size()<<endl;
    for(auto j=vec.begin();j!=vec.end();j++)
    {
        for(auto k = j;k!=vec.end();k++)
        {
            val += arr[*j][*k];
        }
    }
    return val;
}


int main()
{
    cin>>n;
    vector<vector<lli> > arr(n,vector<lli>(n));
    for(lli i=0;i<n;i++)
    {
        for(lli j=0;j<n;j++)
        {
            cin>>arr[i][j];
        }
    }
    //cout<<sum(7,arr);
    lli dp[1<<n];
    for(lli i=0;i<(1<<n);i++)
    {
        dp[i] = sum(i,arr);
        for(lli j=i;j>0;j = i&(j-1))
        {
            dp[i] = max(dp[i] , dp[j]+dp[i^j]);
        }
    }
    cout<<dp[(1<<n) - 1];
}


Measured memory_bytes: 768
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    K, X = map(int, readline().split())

    if 500 * K >= X:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61872
d = gets.chomp.split
s = gets.chomp.split //

s.each do |c|
  case c
  when "N"
    d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
  when "S"
    d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
  when "E"
    d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
  when "W"
    d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
  end
end
#上面表示
puts d[0]

# サイコロchange
# 一つの命令で4面変わり、2面は固定
#実物:配列番号
# N移動命令
# 1 2 : 0 1
# 2 6 : 1 5
# 6 5 : 5 4
# 5 1 : 4 0
# S移動命令
# 1 5 : 0 4
# 5 6 : 4 5
# 6 2 : 5 1
# 2 1 : 1 0
# E移動命令
# 1 4 : 0 3
# 4 6 : 3 5
# 6 3 : 5 2
# 3 1 : 2 0
# W移動命令
# 1 3 : 0 2
# 3 6 : 2 5
# 6 4 : 5 3
# 4 1 : 3 0



Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    vi num(100001,0);
    sort(a.begin(), a.end());
    int64_t res = 0;
    rep(i,a.size()){
        if(a.at(i) > 100000){
            res++;
            continue;
        }
        num.at(a.at(i))++;
    }
    rep(i,100001){
        if(num.at(i)<i){
            res += num.at(i);
        }else if(num.at(i)>i){
            res += abs(num.at(i) - i);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int main()
{
    const char ATCG = 'a';
    const char OTHER = 'o';
    const char* OTHER_STR = "o";

    char input_str[11] = {0};

    if(scanf("%10s", input_str) != 1){
        return 0;
    }

    for(size_t i = 0 ; i < strlen(input_str) ; i++){
        switch(input_str[i]){
            case 'A':
            case 'T':
            case 'C':
            case 'G':
                input_str[i] = ATCG;
                break;
            default:
                input_str[i] = OTHER;
                break;
        }
    }

    char* p = strtok(input_str, OTHER_STR);
    int max_len = 0;

    while(p != NULL){
        int len = strlen(p);
        max_len = max_len > len ? max_len : len;

        p = strtok(NULL, OTHER_STR);
    }

    printf("%d\n", max_len);

    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>

using namespace std;

int main(){

    string s;

    string t;

    cin >> s;

    int m=0;
    int l=0;
    string u;

    for(int i=0;i<s.size();i++){
        for(int j=0;j<s.size()-i+1;j++){
            t = s.substr(i,j);
            bool ok=true;
            for(int k=0;k<t.size();k++){
                if(t[k]=='T' || t[k] == 'A' || t[k] == 'G' || t[k] == 'C') ;
                else ok = false;
            }
            l = t.size();
            if(ok == true && t.size()>m)u=t;
            if(ok) m=max(m,l);
        }
    }

    cout << m << endl;

}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    int cnt = 0;
    char buff[1000];
    for (int x = a; x <= b; ++x) {
      sprintf(buff, "%d", x);
      string s(buff);
      string t = s;
      reverse(t.begin(), t.end());
      cnt += (s == t);
    }
    cout << cnt << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();
		int count = 0;
		while (count < len) {
			int j = sc.nextInt();
			if (j % 2 == 0) {
				if (j % 3 != 0 && j % 5 != 0) {
					break;
				}
			}
			count ++;

		}
		if (count == len) {
			System.out.println("APPROVED");
		} else {
			System.out.println("DENIED");
		}

	}
}


Measured memory_bytes: 23892
#include <algorithm>
#include <iostream>
#include <cmath>
#include <complex>
#include <cstring>
using namespace std;

typedef complex<int> C;
#define EPS (1e-8)

int n, hx, hy, dx, dy;
bool possible, used[21];
C c[21];

double dist(int x, int y) {
	return sqrt((double)x*x + (double)y*y);
}

void dfs(double ct, int x, int y) {
	if (possible) return;
	
	bool end_flag = true;
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			end_flag = false; break;
		}
	}
	if (end_flag) {
		possible = true; return;
	}

	for (int i = 0; i < n; i++) {
		if (used[i]) continue;

		double h2c = dist(x-c[i].real(), y-c[i].imag());
		double d2c = dist(dx-c[i].real(), dy-c[i].imag()) - ct;
		if (h2c + EPS > d2c) {
			return;
		}
	}

	for (int i = 0; i < n; i++) {
		if (used[i]) continue;

		used[i] = true;
		double h2c = ct + dist(x-c[i].real(), y-c[i].imag());
		dfs(h2c, c[i].real(), c[i].imag());
		used[i] = false;
	}
}

void solve() {
	for (int i = 0; i < n; i++) {
		cin>>c[i].real()>>c[i].imag();
	}

	fill(used, used+n, false);	
	//memset(used, false, sizeof used);
	possible = false;

	dfs(0, hx, hy);

	if (possible) {
		cout<<"YES";
	} else {
		cout<<"NO";
	}
	cout<<endl;
}

int main(int argc, const char *argv[]) {
	while (cin>>n>>hx>>hy>>dx>>dy, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 864
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
signed main(void)
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n<3200)
		cout<<"red"<<endl;
	else
		cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int d[20][20];
int t[110][110];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			scanf("%d",&d[i][j]);
		}
	}
	for(int i=0;i<110;i++){
		for(int j=0;j<110;j++){
			for(int k=0;k<a;k++)for(int l=0;l<b;l++){
				t[i][j]=max(t[i][j],d[k][l]-(k+1)*i-(l+1)*j);
			}
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			int v=mod;
			for(int k=0;k<110;k++)for(int l=0;l<110;l++){
				v=min(v,t[k][l]+k*(i+1)+l*(j+1));
			}
			if(v!=d[i][j]){
				printf("Impossible\n");return 0;
			}
		}
	}
	printf("Possible\n");
	printf("%d %d\n",220,109+109+110*110);
	for(int i=0;i<109;i++){
		printf("%d %d X\n",i+1,i+2);
	}
	for(int i=0;i<109;i++){
		printf("%d %d Y\n",i+111,i+112);
	}
	for(int i=0;i<110;i++)for(int j=0;j<110;j++){
		printf("%d %d %d\n",i+1,220-j,t[i][j]);
	}
	printf("1 220\n");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2000000000
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
//gcd,lcmセット
ll gcd(ll a, ll b){
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}
ll lcm(ll a, ll b){	
   return a*b/gcd(a, b);
}
bool isPrime(ll x){
    int i;
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
//dfsではvector<vector<int>> g(n);で◎
int main(){
    int n;
    cin>>n;
    ll cnt[n+1]={0};
  	ll a[n+1]={0};
    REP(i,n){
        cin>>a[i+1];
        cnt[a[i+1]]++;
    }
    //for(int i=1;i<=n;i++)cout<<"cnt["<<i<<"]:"<<cnt[i]<<endl;
	ll full=0;
    REP(j,n) full+=cnt[j+1]*(cnt[j+1]-1)/2;
  	//cout<<"full:"<<full<<endl;
    REP(i,n)cout<</*"Ban_"<<i+1<<":"<<*/full-cnt[a[i+1]]+1<<endl;
}

Measured memory_bytes: 5760
// Identically Colored Panels Connection
import java.util.*;

public class Main {
	static int w, h;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			h = scanner.nextInt();
			w = scanner.nextInt();
			int c = scanner.nextInt();
			if ((h | w | c) == 0)
				break;
			int[][] field = new int[w][h];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					field[j][i] = scanner.nextInt();
			int result = 0;
			for (int i = 1; i < 7; i++) {
				if (i != field[0][0]) {
					int[][] tfield1 = changeField(field, i);
					for (int j = 1; j < 7; j++) {
						if (j != tfield1[0][0]) {
							int[][] tfield2 = changeField(tfield1, j);
							for (int k = 1; k < 7; k++)
								if (k != tfield2[0][0]) {
									int[][] tfield3 = changeField(tfield2, k);
									for (int l = 1; l < 7; l++) {
										if (l != tfield3[0][0]) {
											int[][] tfield4 = changeField(
													tfield3, l);
											if (l == c) {
												result = Math.max(result,
														count(tfield4, 0, 0));
											} else {
												int[][] tfield5 = changeField(
														tfield4, c);
												result = Math.max(result,
														count(tfield5, 0, 0));
											}
										}
									}
								}
						}
					}
					result = Math.max(result, count(tfield1, 0, 0));
				}
			}
			System.out.println(result);
		}
		scanner.close();
	}

	static int[][] changeField(int[][] field, int change) {
		int[][] result = new int[w][h];
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				result[j][i] = field[j][i];
		changeColor(result, change, 0, 0);
		return result;
	}

	static void changeColor(int[][] field, int change, int x, int y) {
		int b = field[x][y];
		field[x][y] = change;
		if (x > 0 && b == field[x - 1][y])
			changeColor(field, change, x - 1, y);
		if (x < w - 1 && b == field[x + 1][y])
			changeColor(field, change, x + 1, y);
		if (y > 0 && b == field[x][y - 1])
			changeColor(field, change, x, y - 1);
		if (y < h - 1 && b == field[x][y + 1])
			changeColor(field, change, x, y + 1);
	}

	static int count(int[][] field, int x, int y) {
		int result = 1;
		int b = field[x][y];
		field[x][y] = 0;
		if (x > 0 && b == field[x - 1][y])
			result += count(field, x - 1, y);
		if (x < w - 1 && b == field[x + 1][y])
			result += count(field, x + 1, y);
		if (y > 0 && b == field[x][y - 1])
			result += count(field, x, y - 1);
		if (y < h - 1 && b == field[x][y + 1])
			result += count(field, x, y + 1);
		return result;
	}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  int x = 0;
  rep(i, n) x ^= a[i];
  rep(i, n) a[i] ^= x;
  cout << a << endl;
}


Measured memory_bytes: 3948
N = int(input())
B = list(map(int,input().split()))
A = []
for i in range(N):
    if i == 0:
        A.append(B[0])
    elif i == N-1:
        A.append(B[i-1])
    else:
        A.append(min(B[i],B[i-1]))
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  int n;cin>>n;
  int a[100010];
  int po=0;
  int ans=0;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=n-1;i>=0;i--){
    if(i!=n-1 && a[i]<a[i+1])po=0;
    ans=max(ans,po);
    po++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]
 
def dfs(idx, a, b, c):
 
    if idx == N:
        if a == 0 or b == 0 or c == 0:
            return 1e9
        
        return abs(A - a) + abs(B - b) + abs(C - c)
    
    x = dfs(idx + 1, a, b, c)
    y = dfs(idx + 1, a + L[idx], b, c) + 10*(a != 0)
    z = dfs(idx + 1, a, b + L[idx], c) + 10*(b != 0)
    w = dfs(idx + 1, a, b, c + L[idx]) + 10*(c != 0)
    return min(x, y, z, w);
 
ans = dfs(0, 0, 0, 0);
print(ans)


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    vector<int> res;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int y, m, d;
        cin >> y >> m >> d;
        int cnt = 0;
        while (y < 1000) {
            while (m <= 10) {
                int days = 19;
                if (m % 2 == 1 or y % 3 == 0) days++;
                while (d <= days) {
                    cnt++;
                    d++;
                }
                d = 1;
                m++;
            }
            m = 1;
            y++;
        }
        res.push_back(cnt);
    }
    for (int i = 0; i < (int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int main()
{
    fast();
    string n;
    cin>>n;
    if(n.find("7")!=string::npos){cout<<"Yes";}
    else cout<<"No";
return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
char s[110];
int main(){
	int n,i,s1,s2;
	scanf("%d%s",&n,s+1);
	s1=s2=0;
	for(i=1;i<=n;i++)(s[i]=='R'?s1:s2)++;
	printf(s1>s2?"Yes":"No");
}

Measured memory_bytes: 128
<?php
// Your code here!
    $n = intval(trim(fgets(STDIN)));
    
    $p = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    $count=0;
    
    for($i=1;$i<$n-1;$i++){
        $array[0]=$p[$i-1];
        $array[1]=$p[$i];
        $array[2]=$p[$i+1];
        
        sort($array);
        
        if($array[1] == $p[$i]){
            $count++;
        }
    }
    echo $count;

?>

Measured memory_bytes: 15964
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=2005;
int n,m;
vector <int> e[N],G[N];
int g[N][N],f[N][N];
int dis[N][N];
void dfs1(int s,int x,int d){
	dis[s][x]=d;
	for (auto y : e[x])
		if (y!=s&&!dis[s][y])
			dfs1(s,y,d+1);
}
void Insert(int a,int b){
	if (f[a][b]==b)
		return;
	if (f[a][b]){
		Insert(f[a][b],b);
		return;
	}
	if (f[b][a]){
		Insert(f[b][a],a);
		return;
	}
	vector <pair <int,int> > newE;
	For(_,0,1){
		g[a][b]=1,f[a][b]=b;
		queue <int> q;
		q.push(b);
		while (!q.empty()){
			int x=q.front();
			q.pop();
			for (auto y : e[x])
				if (dis[a][y]>dis[a][x]){
					if (f[a][y]){
						g[f[a][y]][a]=g[a][f[a][y]]=0;
						newE.pb(mp(f[a][y],b));
					}
					else
						f[a][y]=b,q.push(y);
				}
		}
		swap(a,b);
	}
	for (auto i : newE)
		Insert(i.fi,i.se);
}
int T=0;
int ve[N][N],vis[N];
void dfs(int px,int x){
	if (ve[px][x]==T)
		return;
	ve[px][x]=T;
	vis[x]=1;
	for (auto y : G[x])
		if (dis[px][y]==dis[px][x]+dis[x][y])
			dfs(x,y);
}
int main(){
	n=read(),m=read();
	For(i,1,n-1){
		int x=read(),y=read();
		e[x].pb(y),e[y].pb(x);
	}
	For(i,1,n)
		dfs1(i,i,0);
	while (m--){
		int a=read(),b=read();
		Insert(a,b);
	}
	For(i,1,n)
		For(j,1,n)
			if (g[i][j])
				G[i].pb(j);
	int ans=0;
	For(i,1,n){
		T=i;
		clr(vis);
		for (auto x : G[i])
			dfs(i,x);
		For(j,1,n)
			if (j!=i)
				ans+=vis[j];
	}
	cout<<ans/2<<endl;
	assert(ans%2==0);
	return 0;
}

Measured memory_bytes: 62720
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

S = input()
K = int(input())

cnt_1 = 0
for s in S:
    if s=="1":
        cnt_1 += 1
    else:
        break

if cnt_1>=K:
    print(1)
else:
    print(S[cnt_1])

Measured memory_bytes: 12208
#![allow(non_snake_case)]
use proconio::input;
use std::collections::HashMap;
const M: i64 = 1000000007_i64;
fn main() {
    input! {
        n:usize,
        ab:[(i64,i64);n]
    }
    // 鰯(Ai,Bi)と(Aj,Bj)について、Ai*Aj + Bi*Bj =0になる組み合わせは不可。
    // (0,0)の鰯の数を x とすると、これらは一匹のみの場合のみ追加可能。
    // 両辺を Aj * Bi で割ると、Ai/Bi + Bj/Aj = 0となる。
    // 逆数にして -1 をかけた鰯とは組み合わせられないが、他ならOK。
    // 鰯について、既約分数で表現すれば、Ai/Biは一意に定まる。
    let ab: Vec<(i64, i64)> = ab.into_iter().filter(|&(a, b)| a != 0 || b != 0).collect();
    let zero = (n - ab.len()) as i64;
    let ab: Vec<(i64, i64)> = ab.into_iter().map(|(a, b)| yakubun(a, b)).collect();
    // modPow(2,x)
    let mut mp2 = vec![1i64; n + 1];
    for i in 0..n {
        mp2[i + 1] = mp2[i] * 2 % M;
    }
    let mut group1 = HashMap::new();
    ab.iter().for_each(|&x| {
        *group1.entry(x).or_insert(0) += 1;
    });

    //println!("{:?}", group1);
    let mut ans = 1;
    for &(a, b) in &ab {
        let mut pararells = 0;
        if let Some(v) = group1.get(&(a, b)) {
            pararells += v;
            group1.remove(&(a, b));
        }
        if let Some(v) = group1.get(&(-a, -b)) {
            pararells += v;
            group1.remove(&(-a, -b));
        }
        let mut crosses = 0;
        if let Some(v) = group1.get(&(b, -a)) {
            crosses += v;
            group1.remove(&(b, -a));
        }
        if let Some(v) = group1.get(&(-b, a)) {
            crosses += v;
            group1.remove(&(-b, a));
        }
        //println!("({},{}), p:{}, c:{}", a, b, pararells, crosses);
        ans = ans * ((mp2[pararells] + mp2[crosses] - 1) % M) % M;
    }
    ans = (ans + zero + M - 1) % M;
    println!("{}", ans);
}

// また、bの符号に一致する様に計算する。

fn yakubun(a: i64, b: i64) -> (i64, i64) {
    if b == 0 {
        return (-1, 0);
    }
    if a == 0 {
        return (0, 1);
    }
    let x = if b > 0 {
        num::integer::gcd(a, b)
    } else {
        -num::integer::gcd(a, b)
    };
    return (a / x, b / x);
}


Measured memory_bytes: 26924
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N, M, C;
    scan(N, M, C);
    auto b = readArr!(int)();

    int ans;

    foreach (i ; 0 .. N) {
        auto a = readArr!(int)();

        long s;

        foreach (j ; 0 .. M) {
            s += a[j] * b[j];
        }

        s += C;

        ans += (s > 0);
    }

    writeln(ans);
}














int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int n = s.size();

    int idx = 0;
    ll tumi=0;

    ll ans = 0;
    while(1){
        if(idx>=n) break;
        if(s[idx] == 'A'){
            tumi+=1;
            idx+=1;
            continue;
        } 
        else{
            if(n-idx < 2) break;

            if (s.substr(idx,2)=="BC"){
                ans+=tumi;
                idx+=2;
                continue;
            }
            else{
                tumi=0;
                idx+=1;
                continue;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n; cin>>n;
  vector<int> x(n),y(n);
  rep(i, n) cin>>x[i]>>y[i];
      
  double res=0;
  vector<int> num;
  rep(i, n) num.emplace_back(i);
  do {
    rep(i, n-1) {
      int X=x[num[i]]-x[num[i+1]];
      int Y=y[num[i]]-y[num[i+1]];
      double T=X*X+Y*Y;
      res+=sqrt(T);
    }
  } while (next_permutation(num.begin(), num.end()));
  rep(i, n) res/=(i+1);
  cout<<setprecision(10)<<res<<endl;
}


Measured memory_bytes: 256