akhauriyash/Code-Regression huggingface dataset:
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  VI a(n);
  REP(i, n) cin >> a[i];

  int s = abs(a[0]);
  FOR(i, 1, n) {
    s += abs(a[i-1] - a[i]);
  }
  s += abs(a[n-1]);

  cout << s - abs(a[0]) - abs(a[0] - a[1]) + abs(a[1]) << endl;
  FOR(i, 1, n-1) {
    cout << s - abs(a[i-1] - a[i]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << endl;
  }
  cout << s - abs(a[n-2]-a[n-1]) - abs(a[n-1]) + abs(a[n-2]) << endl;

  return 0;
}


Measured memory_bytes: 2048
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    int n;
    cin >> n;
    int maxp = -1;
    int ret = 0;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ret += a;
        maxp = max(maxp, a);
    }
    ret -= maxp/2;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vector std::vector
#define string std::string
#define sort std::sort
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

template <class T = int>
T in() { T x; std::cin >> x; return x; }
#define output(e) std::cout << e << '\n'

#ifdef LOCAL
#define db std::cout << "L" << __LINE__
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif

//
// Implementation
//

int main() {
  int N = in();
  vector<int> v(N);
  rep(i, N) v[i] = in();
  sort(all(v));

  int ret = N;

  {
    int i = 0;
    while (i < N-2) {
      int a = v[i];
      int b = v[i+1];
      int c = v[i+2];
      if (v[i] == v[i+1] && v[i+1] == v[i+2]) {
        db dv(v[i]) dv(v[i+1]) dv(v[i+2]) de;
        v[i+0] = 0;
        v[i+1] = 0;
        ret -= 2;
        i += 2;
      } else {
        i += 1;
      }
    }
  }

  {
    int i = 0;
    while (i < N-1) {
      if (v[i] == 0) {
        i += 1;
        continue;
      }
      
      if (v[i] == v[i+1]) {
        for (int j=i+2; j<N-1; j++) {
          if (v[j] == 0) {
            continue;
          }
          
          if (v[j] == v[j+1]) {
            db dv(v[i]) dv(v[j]) de;
            v[i] = 0;
            v[j] = 0;
            ret -= 2;
            break;
          }
        }
        i += 2;
      } else {
        i += 1;
      }
    }
  }

  {
    int i = 0;
    while (i < N-1) {
      if (v[i] == 0) {
        i += 1;
        continue;
      }
      
      if (v[i] == v[i+1]) {
        ret -= 2;
        i += 2;
      } else {
        i += 1;
      }
    }
  }

  output(ret);
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
long n, k;
int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

void solve() {
    cin >> n >> k;
    vector<long> x(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    long ans = INFL;
    for (int i = 0; i <= n - k; ++i) {
        ans = min(ans, x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1])));
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
    return 0;
}



Measured memory_bytes: 1024
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
H = np.array(lr())
Hmax = np.maximum.accumulate(H)
answer = (H == Hmax).sum()
print(answer)


Measured memory_bytes: 13200
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let c: Vec<Vec<i32>> = (0..3).map(|_| (0..3).map(|_| read::<i32>()).collect()).collect();
    let a1 = 0;
    let b1 = c[0][0];
    let b2 = c[0][1];
    let b3 = c[0][2];

    let a2 = c[1][0] - b1;
    let a3 = c[2][0] - b1;

    if c[0][0] == (a1 + b1) &&
        c[0][1] == (a1 + b2) &&
        c[0][2] == (a1 + b3) &&
        c[1][0] == (a2 + b1) &&
        c[1][1] == (a2 + b2) &&
        c[1][2] == (a2 + b3) &&
        c[2][0] == (a3 + b1) &&
        c[2][1] == (a3 + b2) &&
        c[2][2] == (a3 + b3) {
            println!("Yes");
        }else{
            println!("No");
        }
    
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    if (N % 2) {
        cout << 0 << '\n';
    } else {
        ll ans = 0;
        rep2(j, 1, 27) {
            ll x = 2 * pow(5, j);
            ans += N / x;
        }
        cout << ans << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
const int W = 3;
const int H = 3;
const int N = 10;
int A[N];

bool isValid(int B[]) {
  for(int i = 0; i < N; ++i) {
    if(A[i] != 0 && A[i] != B[i]) return false;
  }
  return true;
}

int sumLine(int B[], int x, int y, int dx, int dy) {
  int res = 0;
  for(;x >= 0 && x < W && y >= 0 && y < H; x += dx, y += dy) {
    res += B[x+y*W];
  }
  return res;
}

bool count(int B[]) {
  const int mod = B[N-1];
  const int m = sumLine(B,0,0,1,1) % mod;
  if(m != sumLine(B,0,2,1,-1) % mod) return false;
  for(int i = 0; i < 3; ++i)
    if(m != sumLine(B,0,i,1,0) % mod) return false;
  for(int i = 0; i < 3; ++i)
    if(m != sumLine(B,i,0,0,1) % mod) return false;
  return true;
}

int main() {
  while(1) {
    {
      bool flag = false;
      for(int i = 0; i < N; ++i) {
        cin >> A[i];
        if(A[i] != -1) flag = true;
      }
      if(!flag) break;
    }
    int B[N];
    for(int i = 0; i < N; ++i) B[i] = i+1;
    int res = 0;
    do {
      if(!isValid(B)) continue;
      res += count(B);
    } while(next_permutation(B, B+N));
    cout << res << endl;
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

ll pow_mod(ll a, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1) {
		if (st & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}

ll x[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%lld", &x[i]);
	}
	ll ans = 0ll;
	ll cur = 0ll;
	REP(i, 1, n) {
		ll inv = pow_mod(i, MOD - 2);
		cur = (cur * i + 1) % MOD;
		cur = (cur * inv) % MOD;
		ans = (ans + (x[i] - x[i - 1]) * cur) % MOD;
	}
	REP(i, 1, n) {
		ans = (ans * i) % MOD;
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1024
# solution

n = int(input())
a = list(map(int, input().split()))
M = 10**9+7
res = [-1] * (n+1)
for i in range(n+1):
    if res[a[i]] == -1:
        res[a[i]] = i
    else:
        d = a[i]
        l, r = res[d], n-i
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 2):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
for i in range(1, n+2):
    print((cmb(n+1, i, mod)-cmb(l+r, i-1, mod)) % mod)


Measured memory_bytes: 25700
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

ll A,B,C;
ll check(ll a,ll b,ll c){
    if(a%2 ==1 || b%2 ==1 || c%2 ==1)return 1;
    else if(A == B && B == C)return -1;
    else return 0;
}
void calc(){
    
    ll tmpA = A;
    ll tmpB = B;
    ll tmpC = C;
    A = (tmpB+tmpC)/2;
    B = (tmpA+tmpC)/2;
    C = (tmpB+tmpA)/2;
    
}
int main(){

    cin>>A>>B>>C;
    ll t=0;
    while(true){
        if(check(A,B,C) == -1){
            cout<<-1<<endl;
            return 0;
        }
        if(check(A,B,C))break;
        calc();
        t++;
    }
    cout<<t<<endl;
    return 0;
}

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

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

struct edge {
        int to, cost;
};

vector<edge> g[101010];
int subtree[101010];

int n, mid = -1;
long long ans = 0;
int centroid = -1;

void dfs(int v, int p) {
        bool central = true;
        subtree[v] = 1;
        for (auto &e : g[v]) {
                int u = e.to;
                if (u == p) continue;
                dfs(e.to, v);
                central &= (2 * subtree[u] < n);
                int mi = min(subtree[u], n - subtree[u]);
                if (subtree[u] * 2 == n) mid = e.cost;
                ans += (long long) e.cost * mi * 2;
                subtree[v] += subtree[u];
        }
        central &= (2 * (n - subtree[v]) < n);
        if (central) centroid = v;
}

int main() {
        cin >> n;
        rep(i, n - 1) {
                int a, b, c;
                cin >> a >> b >> c;
                a --, b --;
                g[a].push_back((edge) { b, c });
                g[b].push_back((edge) { a, c });
        }
        dfs(0, -1);
        if (mid != -1) {
                ans -= mid;
        } else {
                int diff = (int) 1e9;
                for (auto &e : g[centroid]) {
                        diff = min(diff, e.cost);
                }
                ans -= diff;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 12800
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - : (Colon)
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const long double PI = acosl(-1.0);

/* typedef */

typedef long double ld;

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, h, m;
  scanf("%d%d%d%d", &a, &b, &h, &m);

  ld th = (h * 30 + m * 0.5 - m * 6) * PI / 180;

  ld dx = a - b * cosl(th), dy = b * sinl(th);
  printf("%.20Lf\n", sqrtl(dx * dx + dy * dy));
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  string s;
  int a[26]={};
  cin >> s;
  rep(i,s.size())
  {
    a[s[i] - 'a']++;
  }
  rep(i,26)
  {
    if (!a[i]) {
      cout << (char)('a' + i);
      return 0;
    }
  }
  cout << "None";
  return 0;
}


Measured memory_bytes: 512
word_list = [i for i in input().split()]
num_list = [int(num) for num in input().split()]
ext_word = input()

check_dict = dict(zip(word_list, num_list))
check_dict[ext_word] -= 1

check_list = [str(check_dict[key_val]) for key_val in word_list]
print(check_list[0] + " " + check_list[1])

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

vector<long long> meat_num(51, 1);
vector<long long> all_num(51, 1);

long long solve(int y, long long z){
    if (z == all_num[y]) return meat_num[y];
    if (z <= 1) return 0;
    if (z <= all_num[y - 1] + 1) return solve(y - 1, z - 1);
    return meat_num[y - 1] + 1 + solve(y - 1, z - all_num[y - 1] - 2); 
}

int main(){
    int n; long long x;
    cin >> n >> x;
    for (int i = 0; i < 50; i++) meat_num[i + 1] = meat_num[i] * 2 + 1;
    for (int i = 0; i < 50; i++) all_num[i + 1] = all_num[i] * 2 + 3;
    cout << solve(n, x) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, k;
    cin >> n >> k;
    int max_num = n * (n - 1) / 2 - (n - 1);
    if (k > max_num) {
        cout << -1 << endl;
        return 0;
    }
    int rest = max_num - k;
    vector<pair<int, int>> ans;
    for (int i = 1; i < n; ++i) { 
        ans.push_back(make_pair(0, i));
    }
    //cout << max_num << " " << rest << endl;
    for (int i = 1; i < n; ++i) {
        bool flg = false;
        for (int j = i + 1; j < n; ++j) {
            if (rest == 0) break;
            --rest;
            ans.emplace_back(i, j);
        }
    }
    cout << (int)(ans.size()) << endl;
    for (auto a: ans) {
        cout << a.first + 1 << " " << a.second + 1 << endl;
    }
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    ll t=0,cnt=0;
    for(ll i=0;i<S.size();++i){
        if(S.at(i)=='W'){
            cnt += i-t;
            ++t;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int H,W;
  cin >> H >> W;
  int white = 0;
  vector<vector<char>> b(H,vector<char>(W));
  vector<vector<int>> num(H,vector<int>(W,0));
  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cin >> b.at(i).at(j);
      if(b.at(i).at(j) == '.') white++;
    }
  }

  num.at(0).at(0) = 1;

  int dx[] = {1,-1,0,0},dy[] = {0,0,1,-1};
  queue<pair<int,int>> Q;
  Q.push(make_pair(0,0));
  while(!Q.empty()) {
    pair<int,int> p = Q.front();
    Q.pop();
    int y = p.first,x = p.second;
    for(int i = 0;i < 4;i++) {
      int Y = y + dy[i],X = x + dx[i];
      if(Y < 0 || Y >= H) continue;
      if(X < 0 || X >= W) continue;
      if(b.at(Y).at(X) == '#')continue;
      if(num.at(Y).at(X) == 0) {
        num.at(Y).at(X) = num.at(y).at(x) + 1;
        Q.push(make_pair(Y,X));
      }
    }
  }

  int ans = white - num.at(H-1).at(W-1);
  if(ans == white) cout << -1 << endl;
  else cout << ans << endl;


}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 1e5, maxm = 2e5;

int n, m, col[nax + 1], cnt[3];
V< int > gr[nax + 1];

int dfs(const int v)
{
    if (not col[v]) col[v] = 1;
    int res = 2;
    for (int s : gr[v])
    {
        if (not col[s])
        {
            col[s] = 3 - col[v];
            if (dfs(s) == 1) res = 1;
        }
        if (col[s] == col[v]) res = 1;
    }
    return res;
}

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

    cin >> n >> m;

    for (int i = 0; i < m; ++i)
    {
        int p, q; cin >> p >> q;
        gr[p].push_back(q);
        gr[q].push_back(p);
    }

    for (int i = 1; i <= n; ++i)
        if (not col[i])
        {
            if (gr[i].empty()) ++cnt[0];
            else ++cnt[dfs(i)];
        }

    ll res = 0;
    res += 2 * (ll)cnt[0] * (n - cnt[0]);
    res += (ll)cnt[0] * cnt[0];

    res += 2 * (ll)(cnt[1]) * cnt[2];
    res += (ll)cnt[1] * cnt[1];

    res += 2 * (ll)cnt[2] * cnt[2];

    print(res);
}

Measured memory_bytes: 9088
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


signed main()
{
	speed
	int n,m;cin>>n>>m;
	if(n==m){cout<<"Yes\n";}
	else{cout<<"No\n";}
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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

ll f(ll n){
    if(n % 2 == 0){
        return n / 2;
    }else{
        return 3 * n + 1;
    }
}


int main() {
    ll s;
    cin >> s;

    
    vector<ll> a;
    a.push_back(s);

    while(true){
        a.push_back(f(a[a.size()-1]));
        for(ll i=0;i<a.size()-1;i++){
            if(a[a.size()-1] == a[i]){
                cout << a.size() << endl;
                return 0;
            }
        }
    }
}


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

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

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

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

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

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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1)
    res[n] = 1;
  return res;
}

signed main() {
  int N;
  cin >> N;
  auto pf = prime_factor(N);

  int ans = 0;
  for (auto pr : pf) {
    int num = pr.se;
    int i = 1;
    while (num >= i) {
      ans++;
      num -= i;
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(void){
    long int n, i, min=1000000, max=-1000000, sum=0, x;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> x;
        if(x < min){
            min = x;
        }
        if(x > max){
            max = x;
        }
        sum = sum + x;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}
















Measured memory_bytes: 3096
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int max = 0;
        for (int i=1;i<N;i++){
            String strr = S.substring(0,i);
            String strl = S.substring(i);
            int count = 0;
            boolean[] b1 = new boolean[26];
            boolean[] b2 = new boolean[26];
            for (int j=0;j<strr.length();j++){
                b1[strr.charAt(j)-'a']=true;
            }
            for (int j=0;j<strl.length();j++){
                b2[strl.charAt(j)-'a']=true;
            }
            for (int j=0;j<26;j++){
                if (b1[j]&&b2[j]){
                  count++;
                }
            }
            max = Math.max(max,count);
        }
        System.out.println(max);
    }
}

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

long long gcd(long long a,long long b)
{
  if(a<b)swap(a,b);
  while(b!=0)
  {
    long long r=a%b;
    a=b;
    b=r;
  }
  return a;
}

int main()
{
  long long a,b;cin>>a>>b;
  long long n=gcd(a,b);
  long long n2=n;
  int i;
  int ans=1;
  for(i=2;i<=(int)sqrt(n);i++)
  {
    if(n2%i==0)
    {
      while(n2%i==0)n2/=i;
      ans++;
    }
  }
  if(n2!=1)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 384
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(1,n-1):
    if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
        ans += 1
print(ans)


Measured memory_bytes: 38256
#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 <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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 / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    ll n, m;
    cin >> n >> m;
    map<ll, ll> rensou;
    ll a, b;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        rensou[a] += b;
    }
    ll cnt = 0;
    ll sum = 0;
    for (auto f : rensou)
    {
        cnt += f.second;
        sum += f.first * f.second;
        if (cnt >= m)
        {
            sum -= (cnt - m) * f.first;
            break;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++){
		if((a*i)%b==c) {
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,t) for (auto i=s; i<=t ;i++)
#define per(i,s,t) for (auto i=s; i>=t; i--)
using namespace std;
const int maxn=1e5+10;
int n,m,a[maxn];
int X,L,R,tmp=0,k=0,s=-1,x=0,tim,A,d,p,ans;
inline int mami(int l,int r,int x){
    return max(l,min(r,x));
}
void fun(){
    while(k<n&&a[k+1]<=tim){
        d=s*(a[k+1]-tmp);
        s*=-1;
        x+=d;
        tmp=a[k+1];
        L=mami(0,X,L+d);
        R=mami(0,X,R+d);
        k++;
    }
}
int main(){
    scanf("%d%d",&X,&n);
    L=0,R=X;
    rep(i,1,n) scanf("%d",&a[i]);
    scanf("%d",&m);
    rep(i,1,m){
        scanf("%d%d",&tim,&A);
        fun();
        p=tim-tmp;
        ans=mami(L,R,A+x);
        ans=mami(0,X,ans+s*p);
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int N;
    cin >> N;
    ve<string> S(N);
    vl T(N);
    rep(i,N){
        cin >> S[i] >> T[i];
    }
    string a;
    cin >> a;
    int ans = 0;
    rep(i,N){
        if(a == S[i]){
            reps(j,i+1,N){
                ans += T[j];
            }
            break;
        }
    }
    out(ans);


    return 0;
}


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

using namespace std;

int main()
{
    string S;
    cin>>S;
    int n = (int)S.size();
    long long ans = 0;
    for (int b=1<<(n-1); b<1<<n; b++)
    {
        long long t = 0;
        for (int i=0; i<n; i++)
        {
            t = t*10+S[i]-'0';
            if (b>>i&1)
            {
                ans += t;
                t = 0;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long a,b,t,m,n,l;
    while(cin >> a >> b)
     {
        if(a>=b){
         m=a;
          n=b; 
        }
        else{
         n=a;
         m=b; 
        }
       while(n!=0)
        {
          t = n;
          n = m%n;
          m= t;
        }
        l = a*b / m;
        cout << m << " " << l << endl;
      }
 return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
 using namespace std;
 #define ll long long
 #define maxn 10000005
  int main()
  {
        int t,cnt=0,bnt=0,ant=0,rnt=0;
        cin>>t;
        while(t--)
        {
            string a;
            cin>>a;
            if(a=="AC")cnt++;
            if(a=="TLE")bnt++;
            if(a=="WA")ant++;
            if(a=="RE")rnt++;
        }
        cout<<"AC x "<<cnt<<endl;
        cout<<"WA x "<<ant<<endl;
        cout<<"TLE x "<<bnt<<endl;
        cout<<"RE x "<<rnt<<endl;

  }

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int f(long long n)
{
    int ans = 0;
    while(n > 2){
        n = (n - 1) / 2;
        ++ ans;
    }
    return ans;
}

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

    long long left = 1;
    long long right = LLONG_MAX / 2;
    while(left < right){
        long long mid = (left + right + 1) / 2;
        if(f(mid) > x)
            right = mid - 1;
        else
            left = mid;
    }
    cout << left << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[1000010], invf[1000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n; cin>>n;
    ll x[200020], y[200020];
    for(int i=0; i<n; i++){
        ll x1, y1; cin>>x1>>y1;
        x[i]=x1+y1;
        y[i]=x1-y1;
    }
    sort(x, x+n);
    sort(y, y+n);
    cout<<max(x[n-1]-x[0], y[n-1]-y[0])<<endl;
    return 0;
}

Measured memory_bytes: 6632
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 String S = sc.next();
		 int count = 0;
		 int temp = 0;
		 for(int i=0; i<S.length(); i++) {
			 if(S.charAt(i)=='A'||S.charAt(i)=='T'||S.charAt(i)=='C'||S.charAt(i)=='G') {
				 count++;
			 }else {
				 count = 0;
			 }
			 if(temp < count) {
				 temp = count;
			 }
		 }
		 System.out.print(temp);
	}
}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;n%=10;
    string ans ;
    if(n==3) ans="bon";
    else if(n==0 || n==1 || n==6 || n==8)ans="pon";
    else if(n==2 || n==4 || n==5 || n==7 || n==9)ans="hon";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
#define MOD 924844033
#define MAX 2020
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int g[MAX][MAX][4];
int f[MAX],jc[MAX];
int n,K,m,ans;
int main()
{
	n=read();K=read();m=(n-1)/K+1;
	jc[0]=1;
	for(int i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%MOD;
	g[1][0][0]=1;g[1][1][2]=1;
	for(int i=1;i<m;++i)
		for(int j=0;j<=i;++j)
			for(int k=0;k<4;++k)
			{
				if(!g[i][j][k])continue;
				add(g[i+1][j][k>>1],g[i][j][k]);
				if(!(k&1))add(g[i+1][j+1][k>>1],g[i][j][k]);
				add(g[i+1][j+1][(k>>1)|2],g[i][j][k]);
			}
	f[0]=1;int s=0;
	for(int i=1;i<=K;++i)
	{
		int p=(n-i)/K+1;s+=p;
		for(int j=s;j;--j)
			for(int k=1;k<=p;++k)
				if(j>=k)add(f[j],1ll*f[j-k]*((g[p][k][0]+g[p][k][1])%MOD)%MOD);
	}
	for(int i=0;i<=n;++i)f[i]=1ll*f[i]*jc[n-i]%MOD;
	for(int i=0;i<=n;++i)add(ans,(i&1)?MOD-f[i]:f[i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 61952
#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>;

void Main()
{
  ll N;
  cin >> N;
  vector<ll> a(N);
  ll sum = 0;
  rep(i,N) {
    cin >> a[i]; 
    sum += a[i];
  }
  ll snuke = 0;
  ll arai = sum;
  ll d = 1e18;
  for (int i = 0; i < N-1; i++) {
    snuke += a[i];
    arai -= a[i];
    d = min(d, abs(snuke-arai));
  }
  cout << d << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1792
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val n = readInt()
    //println((1L..n).filter { it % 3L != 0L && it % 5L != 0L }.sum())

    var r = 0
    (1..n).forEach { a ->
        (1..n).forEach { b ->
            (1..n).forEach { c ->
                r += gcd(gcd(a, b), c)
            }
        }
    }
    println(r)
}

fun gcd(a: Int, b: Int): Int {
    if (b == 0)
        return a
    return gcd(b, a % b)
}

Measured memory_bytes: 36644
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

template<typename T>
struct BIT{
    private:
    vector<T> array;
    const int length;
    
    public:

    BIT(int _n) : array(_n+1),length(_n){}

    T sum(int i){
        T s=0;
        while(i>0){
            s+=array[i];
            i -= i&(-i);
        }
        return s;
    }

    T sum(int i,int j){
        T ret1 = sum(i-1);
        T ret2 = sum(j);
        return ret2-ret1;
    }

    void add(int i,T x){
        while(i<=length){
            array[i]+=x;
            i += i&(-i);
        }
    }
};

vector<ll>a,sum;
ll n,k;

vector<int> Compress(vector<ll> &tmp){
    sort(tmp.begin(),tmp.end());
    tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
    vector<int>ans;
    for(int i=0;i<sum.size();i++){
        int id = lower_bound(tmp.begin(),tmp.end(),sum[i])-tmp.begin();
        ans.push_back(id);
    }
    return ans;
}

int main(void){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	ll s = 0;
	sum.push_back(0);
	for(ll i=0;i<n;i++){
		s+=a[i];
		sum.push_back(s-k*(i+1));
	}
	vector<ll>tmp = sum;
	vector<int>A = Compress(tmp);
	BIT<ll>bit = BIT<ll>((int)A.size());
	ll ans = 0;
	for(int i=0;i<A.size();i++){
		ans+=bit.sum(A[i]+1);
		bit.add(A[i]+1,1);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int v;
        cin >> v;
        ans += v-i-1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
/*************************************************************************
	> File Name: roadconstruction.cpp
	> Author: 
	> Mail: 
	> Created Time: Mon 09 Jul 2018 11:08:56 AM CST
 ************************************************************************/

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;

const int INF = 1e9;

struct edge{
    int to,value,cost;
    edge(){}
    edge(int a,int b,int c):to(a),value(b),cost(c){}
};

typedef pair<int,int> P;
vector<vector<edge> > G(20001);
int d[20001];
int dc[20001];
int V,E;
int sum = 0;

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+20001,INF);
    fill(dc,dc+20001,INF);
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.value){
                d[e.to] = d[v] + e.value;
                que.push(P(d[e.to],e.to));
                dc[e.to] = e.cost; 
            }
            else if(d[e.to]==d[v]+e.value){
                dc[e.to] = min(dc[e.to],e.cost);
            }
        }
    }
}

int main(){
    while(scanf("%d%d",&V,&E)!=-1){
        if(V==0&&E==0)break;
        for(int i=0;i<20001;i++)G[i].clear();
        sum = 0;
        for(int i=0;i<E;i++){
            int a,b,c,d;
            scanf("%d%d%d%d",&a,&b,&c,&d);
            a--;
            b--;
            G[a].push_back(edge(b,c,d));
            G[b].push_back(edge(a,c,d));
        }
        dijkstra(0);
        for(int i=1;i<V;i++)sum+=dc[i];
        printf("%d\n",sum);
    }
    return 0;
}



Measured memory_bytes: 5004
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long INF=1e18;
int main(){
	int N;cin>>N;
	char s[N][10];string st[N]={};
	rep(i,0,N){
		rep(j,0,10) cin>>s[i][j];
		sort(s[i],s[i]+10);
		rep(j,0,10) st[i]+=s[i][j];
	}sort(st,st+N);
	string temp=" ";
    long ans=0,count=0;
	rep(i,0,N){
		if(st[i]==temp){
            count++;
        }else{
            ans+=count*(count-1)/2;
            count=1;
            temp=st[i];
        }
	}cout<<ans+count*(count-1)/2<<endl;
    //print(st,N);
}


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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
	cin >> n;
	vector<ll> ma(n);
	vector<ll> mb(n,0);

	REP(i,n) cin >> ma[i];
	REP(i,n) mb[ma[i]-1]=i+1;
	REP(i,n) cout << mb[i] << " ";
  cout  << endl;
}


Measured memory_bytes: 4824
#include<stdio.h>
int main()
{
    int x,y;
    scanf("%x%x",&x,&y);
    if(x>y){
        printf(">\n");
        //printf("%d>%d\n",x,y);
    }else if(x==y){
        printf("=\n");
        //printf("%d=%d\n",x,y);
    }else if(x<y){
        printf("<\n");
        //printf("%d<%d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    int n,ans=0;double t,a,sa=500000;cin>>n>>t>>a;
    for(int i=0;i<n;i++){
        double x,y;cin>>x;
        y=t-x*0.006-a;
        if(y<0)y*=-1;
        sa=min(y,sa);
        if(sa==y){
            ans=i;
        }
    }
    cout<<ans+1<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,f[105];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	in(n);f[4]=f[7]=1;
	for(int i=8;i<=n;i++)
	f[i]=f[i-4]|f[i-7];
	if(f[n]==0)printf("No\n");
	else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
s = list(input())
sl = len(s)
sample1 = ['0' if e % 2 == 0 else '1' for e in range(sl)]
c1, c2 = 0, 0
for i in range(sl):
    if sample1[i] != s[i]:
        c1 += 1
    else:
        c2 += 1
print(min(c1, c2))

Measured memory_bytes: 4652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.StringTokenizer;

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String c1 = sc.next();
        String c2 = sc.next();
        
        String c11 = String.valueOf(c1.charAt(0));
        String c12 = String.valueOf(c1.charAt(1));
        String c13 = String.valueOf(c1.charAt(2));
        String c21 = String.valueOf(c2.charAt(0));
        String c22 = String.valueOf(c2.charAt(1));
        String c23 = String.valueOf(c2.charAt(2));
        
        if (c11.equals(c23) && c12.equals(c22) && c13.equals(c21)) {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }          
    
    }
}

Measured memory_bytes: 22996
#include<iostream>
using namespace std;
int main(){
	int a;
	cin >> a;
	for (int i = 3; i <= a; i++){
		if (i % 3 == 0){
			cout << " " << i;
		}
		else{
			int x = i;
			while (x!=0){
				if (x % 10 == 3) {
					cout << " " << i; break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3092
//file_name:ABC65_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll a[n+1] = {};
    rep(i,n){
        scanf("%lld",&a[i+1]);
    }
    ll flag[n+1] = {};


    ll ans = 0;
    int now = 1;
    while(true){
        if(flag[now]>1){
            ans = -1;
            break;
        }
        if(now == 2){
            break;
        }
        flag[now]++;
        now = a[now];
        ans++;

    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
N = int(input())
h = [int(x) for x in input().split()]
DP=[0]*(N+1)
DP[2] = DP[1] + abs(h[0]-h[1])
for i in range(3,N+1):
    DP[i] = min(DP[i-2] + abs(h[i-3]-h[i-1]),DP[i-1] + abs(h[i-2]-h[i-1]))
print(DP[N])

Measured memory_bytes: 13928