akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

int N, A, B;
mint count(int x) {
    // nCx
    mint res = 1;
    rep(i, 0, x) res *= N - i;
    rep(i, 1, x + 1) res /= i;
    return res;
}
void _main() {
    cin >> N >> A >> B;

    mint ans = (mint(2) ^ N) - 1;
    ans -= count(A);
    ans -= count(B);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c&&b!=c)
    {
        cout<<c;
    }
    else if(a==c&&a!=b&&c!=b)
    {
        cout<<b;
    }
    else   cout<<a;




    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,m,a,b,ans=0;
    priority_queue<lli> val;
    lli i,j;
    cin>>n>>m;
    rep(i,0,n){
        cin>>a;
        val.push(a);
    }
    rep(i,0,m){
        b=val.top();
        b/=2;
        val.pop();
        val.push(b);
    }
    rep(i,0,n){
        ans+=val.top();
        val.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long D){
  cout<<N/(2*D+1)+(N%(2*D+1)>0?1:0)<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    solve(N, D);
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
from string import ascii_uppercase as alphabet

def main():
    H, W = map(int, sys.stdin.readline().split())
    table = np.array(sys.stdin.read().split(), dtype='U5').reshape(H, W)

    for i in range(H):
        for j in range(W):
            if table[i][j] == 'snuke':
                ans = alphabet[j] + str(i+1)
                print(ans)
                sys.exit()
                
if __name__ == '__main__':
    main()

Measured memory_bytes: 12480
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;  
#define min_heap(t) priority_queue<t,vector<t>,greater<t>>
#define max_heap(t) priority_queue<t>
#define ordered_set(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define orderKey order_of_key
#define findOrder find_by_order
#define F first
#define S second
#define pb emplace_back 
#define mp make_pair
#define f(i,x,y) for(i=x;i<y;i++) 
#define fo(i,x,y) for(i=x;i>=y;i--)
#define all(v) v.begin(),v.end()
#define ss(v) stable_sort(all(v))
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n' 
#define pi  3.14159265358
long long po(long long int m,long long int n){
long long i=1; 
while(n>0)
{
    if(n%2==1)
      i=(i*m);
    n=n/2;
    m=(m*m);
}
return(i);
}
void solve(void){  
    ll n,i,k,j;
    cin>>n>>k;
    vector<ll>v(n),dp(n,3e18);
    for(auto &x:v){
        cin>>x;
    }  
    dp[0]=0;
    for(i=1;i<n;i++){
        for(j=i-1;j>=0&&i-j<=k;j--){
            dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
        }
    } 
    cout<<dp[n-1];
}
int main(void){
    fastio
    ll __=1;
    //cin>> __;
    while(__--){
        solve();
    }
    return 0;
}

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


void solve() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;

  vector<int> keta(40, 0);
  int X = n;
  int sho, amari;
  for (int i = 40; i > 0; i--) {
      sho = X / (int)pow(k, (i-1));
      amari = X % (int)pow(k, (i-1));
      keta[40 - i] = sho;
      X = amari;
  }
//   for (auto a: keta) {
//       cout << a;
//   }
//   cout << endl;

  int count;
  for (int i = 0; i < 40; i++) {
      if (keta[i] != 0) {
          count = i;
          break;
      }
  }
  cout << 40 - count << endl;
}

int main() {
  solve();
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

    sort(A.rbegin(), A.rend());

    ll x = 0;
    ll y = 0;
    REP(i, N){
        if(i%2 == 0){
            x += A[i];
        }
        else{
            y += A[i];
        }
    }

    cout << x - y << endl;
    return 0;
}

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

typedef long long ll;
using namespace std;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};

vector <vector<Edge> > a(100000+1);
int ans[100000] = {};

void dfs(int from, int now) {
    //cout << a[now].size() << endl;
    for (int i = 0; i < int(a[now].size()); i++) {
        if (a[now][i].to == from) continue;
        //cout << a[now][i].to << " " << from << endl;
        if (a[now][i].weight % 2) {
            ans[a[now][i].to] = 1 - ans[now];
        } else {
            ans[a[now][i].to] = ans[now];
        }
        //cout << from+1 << " "  << a[from][i].to+1 << endl;
        dfs(now, a[now][i].to);
    }
}

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

    for (int i = 0; i < n-1; i++) {
        int from, to, weight;
        cin >> from >> to >> weight;
        from--; to--;
        a[from].push_back(Edge(to, weight));
        a[to].push_back(Edge(from, weight));
    }

    ans[1] = 0;
    dfs(-1, 0);
    
    for (int i = 0; i < n; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 9216
local n = io.read("*n")
local t = {}
local imos = {}
for i = 1, n + 1 do
  t[i] = io.read("*n")
  imos[i] = 0
end
imos[n + 2] = 0
local rem = 1
local score = 0
local stage = 0
for i = 1, n + 1 do
  local v = t[i]
  while rem < v and stage < i do
    score = score + rem * (i - stage)
    imos[stage + 1] = imos[stage + 1] + rem
    imos[i] = imos[i] - rem
    stage = stage + 1
    v = v - rem
    rem = imos[stage]
    imos[stage + 1] = imos[stage + 1] + imos[stage]
  end
  if i <= stage then
    score = -1
    break
  end
  score = score + v * (i - stage)
  rem = rem - v
  imos[stage + 1] = imos[stage + 1] + v
  imos[i] = imos[i] - v
end
print(score)


Measured memory_bytes: 6404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int h,w;
  cin>>h>>w;
  vector<string>  s;
  for(int i=0;i<h;i++){
    string tmp;
    cin>>tmp;
    s.push_back(tmp);
    s.push_back(tmp);
  }
  for(int i=0;i<2*h;i++){
    cout<<s[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#coding: UTF-8
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(N):
  ans.append(0)
for i in range(N):
  ans[A[i] - 1] = i + 1 
ans = list(map(str, ans))
ans = " ".join(ans)
print(ans)

Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

#include<atcoder/dsu>
using namespace atcoder;

int main() {
    init();

    int n, q; cin >> n >> q;
    dsu d(n);
    while (q--) {
        int t, a, b; cin >> t >> a >> b;
        if (t == 0)d.merge(a, b);
        else print(d.same(a, b));
    }

    return 0;
}

Measured memory_bytes: 4012
import bisect as b

N = int(input())
P = list(map(int, input().split()))
P.sort()
S = list(set(P))
S.sort()

res = 0
for n, s in enumerate(S):
    i = b.bisect_right(P, s)
    if i == N // 2:
       res = S[n + 1] - s
    elif i > N // 2:
        break

print(res)


Measured memory_bytes: 14396
//https://atcoder.jp/contests/arc100/tasks/arc100_b
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;
	std::vector<int> a(n);
	int64_t s1=0,s2=0,s3=0,s4=0;
	for(int& x:a){
		std::cin>>x;
		s4+=x;
	}
	int i=0,k=0;
	int64_t ans=1e18;
	for(int j=0;j<n;){
		if(0<i&&i<j&&j<k&&k<n){
			ans=std::min(ans,
					std::max({s1,s2,s3,s4})-
					std::min({s1,s2,s3,s4}));
		}

		s2+=a[j];s3-=a[j];++j;
		while(i<n&&std::abs(s1+a[i]-(s2-a[i]))<std::abs(s1-s2)){
			s1+=a[i];s2-=a[i];++i;
		}
		while(k<n&&std::abs(s3+a[k]-(s4-a[k]))<std::abs(s3-s4)){
			s3+=a[k];s4-=a[k];++k;
		}
	}
	std::cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>

#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <stdbool.h>
#include<ctime>

#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf ",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define MOD  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int, int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph;


signed main(){
	ll n;
	cin >> n;
	double res = 2.0 * pi * n;
	pfd(res);




	return 0; 
}

Measured memory_bytes: 3728
import java.util.*;

public class Main {
    static Scanner scanner;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        int n = nextInt();
        int k = nextInt();
        List<Integer> list =new ArrayList<>();;
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        Collections.sort(list);
        int ret = 0;
        for (int i = 0; i < k; i++) {
            ret += list.get(i);
        }
        System.out.println(ret);
    }

    public static void println(Object o) {
        System.out.println(o);
    }

    public static void print(Object o) {
        System.out.print(o);
    }

    public static void printf(String format, Object... o) {
        System.out.printf(format, o);
    }

    public static int nextInt() {
        return Integer.parseInt(scanner.next());
    }

    public static long nextLong() {
        return Long.parseLong(scanner.next());
    }

    public static double nextDouble() {
        return Double.parseDouble(scanner.next());
    }

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static void nextLine() {
        scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        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;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

Measured memory_bytes: 32360
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 202
using namespace std;
int n,i,a[N],ans;
int read()
{
	char c=getchar();
	int w=0;
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w;
}
int main()
{
	n=read();
	for(i=1;i<=2*n;i++) a[i]=read();
	sort(a+1,a+2*n+1);
	for(i=1;i<=2*n;i+=2) ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
int n, m, q;
vi a(51), b(51), c(51), d(51);

int ans = 0;
void solve(vi &v){ 
    if(v.size() == n) {
        int res = 0;
        for(int i = 1; i <= q; i++) {
            if(v[b[i] - 1] - v[a[i] - 1] == c[i]) res += d[i];
        }
        ans = max(ans, res);
        return;
    }
    for(int j = v.back(); j <= m; j++) {
        v.pb(j);
        solve(v);
        v.pop_back();
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> n >> m >> q;
    for(int i = 1; i <= q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    for(int i = 1; i <= m; i++) {
        vi v = {i};
        solve(v);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <set>
#include <utility>

using namespace std;

using Pii = pair<int, int>;

constexpr int V_MAX = 100000;
constexpr int E_MAX = 100000;

vector<Pii> graph[V_MAX+1];
vector<int> outdegree(V_MAX+1, 0), used(V_MAX+1, 0);
set<Pii> ans;

void dfs(int node, int par) {
    used[node] = 1;
    for(Pii child: graph[node]) {
        if(child.first == par) continue;
        if(!used[child.first]) {
            dfs(child.first, node);
            if(outdegree[child.first] % 2) {
                outdegree[node] = 1-outdegree[node];
                outdegree[child.first] = 1-outdegree[child.first];
                if(child.second) {
                    if(ans.find({node, child.first}) == ans.end()) {
                        ans.insert(Pii(child.first, node));
                        continue;
                    }
                } else {
                    if(ans.find({child.first, node}) == ans.end()) {
                        ans.insert(Pii(node, child.first));
                        continue;
                    }
                }
            }
        }
        if(child.second) {
            if(ans.find({child.first, node}) == ans.end()) ans.insert(Pii(node, child.first));
        } else {
            if(ans.find({node, child.first}) == ans.end()) ans.insert(Pii(child.first, node));
        }
        
    }
}

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

    for(int i=0;i<m;++i){
        cin >> a >> b;
        graph[a].emplace_back(b, 1);
        graph[b].emplace_back(a, 0); // 逆辺
        outdegree[a] = 1-outdegree[a];
    }
    if(m % 2) {
        cout << -1 << endl;
        return 0;
    }

    dfs(1, -1);

    for(Pii e: ans) {
        cout << e.first << " " << e.second << endl;
    }
}


Measured memory_bytes: 21760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0045
{
    public class Program

    {
        public static void Main(string[] args)
        {

            List<Tuple<int, int>> salesInformation = new List<Tuple<int, int>>();
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) break;

                int[] items = Array.ConvertAll(line.Trim().Split(','), e => int.Parse(e));
                salesInformation.Add(new Tuple<int, int>(items[0], items[1]));
            }

            Console.WriteLine(salesInformation.Select(x => x.Item1 * x.Item2).Sum());
            Console.WriteLine(Math.Round(salesInformation.Select(x => x.Item2).Sum() / (decimal)salesInformation.Count(),0,MidpointRounding.AwayFromZero));
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 18348
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2000 * 1000 + 47;

struct point
{
	LL x, y;
	int type, i;
	point() {}
	point(LL x1, LL y1, int type1, int i1)
	{
		x = x1;
		y = y1;
		type = type1;
		i = i1;
	}
};

struct segment
{
	LL x1, x2, y;
};

point P[MAX];
point Q[MAX];
segment S[MAX];
multiset<LL> sett;
vector<int> g[MAX];
int v, n, r;
int qsz;
int sz;
LL cx, cy;

LL square(LL x1, LL y1, LL x2, LL y2, LL x3, LL y3)
{
	return (x2 - x1) * (y2 - y1) - (x3 - x1) * (y2 - y1);
}

bool cw(const point& a, const point& b)
{
	LL s = square(cx, cy, a.x, a.y, b.x, b.y);
	if (s == 0) return a.y > a.y;

	return square(cx, cy, a.x, a.y, b.x, b.y) < 0;
}

bool cmp(const point& a, const point& b)
{
	return cw(a, b);
}

bool inside(LL x, LL y)
{
	bool g = (y - cy) * v + cx > x;
	bool s = -(y - cy) * v + cx < x;
	return g && s;
}

LL getMin(LL x, LL y)
{
	LL ans = LINF;
	FOR(i, 0, n)
	{
		if (S[i].y <= y) continue;
		LL xx = (S[i].y - y) * v + x;

		if (S[i].x1 < xx && xx < S[i].x2) ans = min(ans, S[i].y);
	}

	return ans;
}

vector<int> RES;
vector<int> V;
double ans = LINF;

void dfs(int v)
{
	V.PB(v);
	LL val = getMin(P[v].x, P[v].y);

	if (val > r && (r - P[v].x) / v < ans)
	{
		ans = (r - P[v].x) / v;
		RES = V;
	}

	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to);
	}

	V.pop_back();
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	FOR(k1, 0, n + 1)
	{
		FOR(k2, 0, m + 1)
		{
			if (m * k1 + (n - 2 * k1) * k2 == k)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 47360
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

vector<int> G[100100];
int to[100100];

int main(){
	int n,m; cin >> n >> m;
	vector<int> a(n+m-1),b(n+m-1);
	for(int i=0;i<n+m-1;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back(b[i]);
		to[b[i]]++;
	}
	int parent;
	for(int i=0;i<n;i++){
		if(to[i]==0)parent=i;
	}
	vector<int> dist(n,0);
	queue<int> q;
	q.push(parent);
	while(q.empty()==false){
		int v=q.front();
		q.pop();
		for(int p:G[v]){
			to[p]--;
			dist[p]=max(dist[p],dist[v]+1);
			if(to[p]==0){
				q.push(p);
			}
		}
	}
	vector<int> par(n,-1);
	for(int i=0;i<n+m-1;i++){
		int f=a[i]; int t=b[i];
		if(dist[t]-dist[f]==1){
			par[t]=f;
		}
	}
	for(int i=0;i<n;i++){
		cout << par[i]+1 << endl;
	}
}

Measured memory_bytes: 8192
program A175
    implicit none
    character(3) :: S
    integer(8) :: i, d
    integer(8), dimension(:) :: ans(3)

    read(5,*) S

    d = 0
    ans = 0
    do i = 1, 3
        if (S(i:i) == "R") then
            d = d + 1
            ans(i) = d
        else
            d = 0
            ans(i) = d

        end if
    end do

    write(6,*) maxval(ans)
    



end program A175


Measured memory_bytes: 2852
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#pragma region
#define rep(i,n) for (int i=0; i < int(n); i++)
struct UnionFind
{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }

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

    if (x == y) return;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

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

  int size(int x) {
    return sizes[find(x)];
  }
};
#pragma endregion
int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    vector<vector<int>> friends(N), blocks(N);
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        friends[A[i] - 1].push_back(B[i] - 1);
        friends[B[i] - 1].push_back(A[i] - 1);
        uf.unite(A[i] - 1, B[i] - 1);
    }
    for (int i = 0; i < K; i++) {
        cin >> C[i] >> D[i];
        blocks[C[i] - 1].push_back(D[i] - 1);
        blocks[D[i] - 1].push_back(C[i] - 1);
    }
    
    unordered_map<int, unordered_set<int>> um;
    for (int i = 0; i < N; i++) {
        um[uf.find(i)].insert(i);
    }
    for (int i = 0; i < N; i++) {
        int t = um[uf.find(i)].size() - 1 - friends[i].size();
        //cout << um[uf.find(i)].size() << endl;
        for (int j : blocks[i]) if (uf.same(i, j)) t--;
        cout << t << " ";
    }
    cout << endl;
}

Measured memory_bytes: 25124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) a.begin(), a.end()

int main(){
    string S;
    cin >> S;
    int n = S.size();
    int cnt = 1;
    int ans = 0;
    for(int index = 0; index < n; index++){
        //cout << index << endl;
        int cnt = 1;
        int t = index;
        while(t < n - 1  && S[t] == S[t+1]){
            cnt++;
            t++;
        }
        //cout << "t " << t << endl;
        if(t == n - 1){
            if(cnt % 3 == 0){
                ans += cnt/3 * 2;
                index += cnt - 1;
            }else if(cnt % 3 == 1){
                ans += (cnt + 2 ) /3 * 2 - 1;
                index += cnt - 1;
            }else{
                ans += (cnt + 1 ) /3 * 2 - 1;
            }
            break;
        }else{
        if(cnt % 3 == 0){
            ans += cnt/3 * 2;
            index += cnt - 1;
        }else if(cnt % 3 == 1){
            ans += (cnt + 2 ) /3 * 2 - 1;
            index += cnt - 1;
        }else{
            ans += (cnt + 1) / 3 * 2;
            index += cnt;
        }
        }
        //cout << "ans "<<  ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,m;
 cin>>n>>m;
 vector<int> home(m,0);
 long long int sum=0;
 for(int i=0;i<m;i++){
     cin>>home[i];
     sum+=home[i];
 }
if(sum>n){
    cout<<-1<<endl;
}
else if(sum<n){
    cout<<n-sum<<endl;
}
else{
    cout<<0<<endl;
}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int ans = 0;
  for(int i = 1;i < a+1;i++){
    int u = 0;
    int h = i; 
    while(h!=0){
      h/=10;
      u++;}
    if(u%2==1)ans++;}
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, W, v[1002], w[1002]; // v[i],w[i] := iツ氾板姪堋づ個品ツ閉ィツづ個可ソツ値ツ、ツ重ツつウ
int dp[1002][1002]; // dp[i][j] := iツ氾板姪堋づ個品ツ閉ィツづ慊づ考ツ猟カツつオツつスツ篠楪づ個、ツ重ツつウjツづ可つィツつッツづゥツ催妥・ツづ個可ソツ値
void solve() {
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (j < w[i]) {
        dp[i+1][j] = dp[i][j];
      } else {
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      }
    }
  }
  int *itr = max_element(dp[N], dp[N]+W+1);
  printf("%d\n%d\n", *itr, itr - dp[N]);
  // int ans = -1, itr = -1;
  // for (int i = 0; i <= W; ++i) if (ans < dp[N][i]) ans = dp[N][i], itr = i;
  // printf("%d\n%d\n", ans, itr);
}

int main() {
  int z = 1;
  while (scanf("%d",&W),W) {
    scanf("%d",&N);
    rep(i,N) scanf("%d,%d",v+i,w+i);
    printf("Case %d:\n", z);
    solve();
    ++z;
  }
  return 0; 
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    cin >> N;
    map<string, ll> n, m;
    set<string> S;
    ll maxi = 0;
    rep(i, N) {
        string temp;
        cin >> temp;
        n[temp]++;
        S.insert(temp);
    }
    cin >> M;
    rep(i, M) {
        string temp;
        cin >> temp;
        m[temp]++;
        S.insert(temp);
    }
    iter(s, S) maxi = max(maxi, n[s] - m[s]);
    cout << maxi << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define All(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}



int main() {
    double N;
    cin >> N;
    //sort(ALL(A));
    cout  << (N-((int)N/2))/N << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N, all = 0;
  cin >> N;
  int* A = new int[N + 2];
  A[0] = A[N + 1] = 0;
  for(int i = 1; i < N + 1; ++i){
    cin >> A[i];
    all += abs(A[i] - A[i-1]);
  }
  all += abs(A[N+1] - A[N]);
  for(int i = 1; i < N + 1; ++i){
    cout << all - abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]) + abs(A[i+1] - A[i-1]) << endl;
  }
  delete[] A;
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi a(13,0);
    rep(i,n){
      int x;
      cin>>x;
      a[x/10]++;
    }
    rep(i,6)
      cout<<a[i]<<endl;
    cout<<a[6]+a[7]+a[8]+a[9]+a[10]+a[11]+a[12]<<endl;
  }
}

Measured memory_bytes: 2988
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long K, S;
	cin >> K >> S;
	long long ans = 0;
	for (long long i = 0; i <= K; i++) {
		for (long long j = 0; j <= K; j++) {
			if (S - i - j <= K && S - i - j >= 0) ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int (i)=0; (i) < (n); ++(i))
#define FOR(i,a,b) for (int (i)=(a); (i) < (b); ++(i))
using namespace std;

int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

int C[2][1000000];

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int X, Y;
  cin >> X >> Y;

  // (2,1)と(1,2)を基底ベクトルとする斜向座標に変換する。
  int tmp1 = 2 * X - Y;
  int tmp2 = -X + 2 * Y;
  if (tmp1 % 3 != 0 || tmp2 % 3 != 0) {
    cout << "0" << endl;
    return 0;
  }

  int x = tmp1 / 3;
  int y = tmp2 / 3;

  if (x < 0 || y < 0) {
    cout << "0" << endl;
    return 0;
  }

  // 答えは組み合わせ数x+yCx
  int a; // (x+y)! (mod)
  int b; // x! (mod)
  int c; // y! (mod)

  a = 1;
  for (int i=2; i<=x+y; i++) {
    a *= i;
    a %= MOD;
  }

  b = 1;
  for (int i=2; i<=x; i++) {
    b *= i;
    b %= MOD;
  }

  c = 1;
  for (int i=2; i<=y; i++) {
    c *= i;
    c %= MOD;
  }

  a = (a * modinv(b, MOD)) % MOD;
  a = (a * modinv(c, MOD)) % MOD;

  cout << a << endl;

  return 0;
}


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

class Program
{
	static void Main(string[] args)
	{
		string[] nm = Console.ReadLine().Split();

		int n = int.Parse(nm[0]);
		int m = int.Parse(nm[1]);

		int[] cs = Console.ReadLine().Split().Select(str => int.Parse(str)).ToArray();

		int[] minCounts = new int[50001];

		// コイン1枚で実現できる金額には枚数1を入れておく
		for (int ci = 0; ci < m; ci++)
		{
			minCounts[cs[ci]] = 1;
		}

		// 1から順番に辿る
		for (int i = 1; i <= n; i++)
		{
			if (minCounts[i] > 0) continue;
			minCounts[i] = GetMinCounts(i, minCounts);
		}
		System.Console.WriteLine(minCounts[n]);
	}

	// Kを実現する最小コイン枚数を返す
	static int GetMinCounts(int k, int[] minCounts)
	{
		// 頭と後ろからの組み合わせで最小値を計算
		int min = k;
		for (int j = 1; j < k / 2 + 1; j++)
		{
			//if (k - j < j) return min;
			int current = minCounts[k - j] + minCounts[j];
			if (current < min) min = current;
		}
		return min;
	}
}



Measured memory_bytes: 9840
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int dp[2][200000];
vector<int> vertexs[200000];
int cnt[2][200000];
vector<int> check[2][200000];
void solve(){
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	REP(i, n) {
		dp[0][i+1] = 1e9;
		dp[1][i+1] = 1e9;
	}
	dp[0][s] = 0;
	dp[1][t] = 0;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	REP(tea, 2) {
		queue<int> next;
		next.push(s);
		while (next.empty() == false) {
			int now = next.front();
			next.pop();
			cnt[tea][dp[tea][now]]++;
			check[tea][dp[tea][now]].push_back(now);
			for (auto x : vertexs[now]) {
				if (dp[tea][x] > dp[tea][now] + 1) {
					dp[tea][x] = dp[tea][now] + 1;
					next.push(x);
				}
			}
		}
		swap(s, t);
	}
	int ans = 0;
	for (int i = 0; i <= dp[0][t] - 2; ++i) {
		ans += cnt[0][i] * cnt[1][dp[0][t] - 2 - i];
		for (auto x : check[0][i]) {
			cnt[1][dp[1][x]]--;
		}
	}
	cout << ans << endl;
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 25972
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int X[5];
int i,k;
for(i=0;i<5;i++){
cin>>X[i];
  if(X[i]==0){
  k=i;
  }
}
cout<<endl;
 cout<<k+1;
 
 
return 0;
}

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

#define N 1000001

int main() {

	vector<bool> check(N, false);
	vector<long long> prime;
	
	
	for(long long i = 2; i < N; ++i){
		if(!check[i]) prime.push_back(i);
		for(long long j = 2; i * j < N; ++j){
			check[i * j] = true;
		}
	}
	
	int n;
	
	while(cin >> n){
		auto it = lower_bound(prime.begin(), prime.end() , n+1);
		
		cout << distance(prime.begin(), it) << endl;
	}

	return 0;
}


Measured memory_bytes: 3860
n = int(input())
l = list(map(int,input().split()))
count = 1
if l.count(0) != 0:
  print(0)
else:
  for i in range(n):
    count *= l[i]
    if count > 1000000000000000000:
      print("-1")
      break
  if count <= 1000000000000000000:
    print(count)
  


Measured memory_bytes: 21588
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
ll a, b, c, x, y;
int main() {
    IO;
   
    cin >> a >> b >> c >> x >> y;
    ll res = LINF;
    res = min(res, a * x + b * y);
    res = min(res, 2 * c * min(x, y) + (x - min(x, y)) * a + (y - min(x, y)) * b);
    res = min(res, 2 * c * max(x, y));
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=3010,Mod=1e9+7,INV2=500000004;
int n,Q,a[N],f[N][N];

int main()
{
	n=gi();Q=gi();int pw=1;
	for(int i=1;i<=n;i++)a[i]=gi();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)f[i][j]=(a[i]<a[j]);
	while(Q--)
	{
		int x=gi(),y=gi();pw=2ll*pw%Mod;
		f[x][y]=f[y][x]=1ll*INV2*(f[x][y]+f[y][x])%Mod;
		for(int i=1;i<=n;i++)
			if(x!=i&&i!=y)
			{
				f[x][i]=f[y][i]=1ll*INV2*(f[x][i]+f[y][i])%Mod;
				f[i][x]=f[i][y]=1ll*INV2*(f[i][x]+f[i][y])%Mod;
			}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)ans=(ans+f[i][j])%Mod;
	printf("%lld\n",1ll*ans*pw%Mod);
	return 0;
}


Measured memory_bytes: 35584
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::pair;using std::set;using std::string;using std::vector;
using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;
#define ff first
#define ss second
#define pb emplace_back
template<typename T>void _dbg(const char*_s,T _h){cerr<<_s<<" = "<<_h<<"\n";}
template<typename T,typename...Ts>void _dbg(const char*_s,T _h,Ts..._t){int _b=0;while(((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',')cerr<<*_s++;cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);}
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 
#endif
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#endif
}}init;

const int MAXN = 2e5 + 1;
int a[MAXN], b[MAXN];
void no() {
    cout << "-1\n";
    exit(0);
}

int leqpow[MAXN];
struct sparse_table_init {
    sparse_table_init() {
        for (int i = 2; i < MAXN; ++i)
            leqpow[i] = leqpow[i / 2] + 1;
    }
} sparse_table_init;
template<typename T, class compare=std::less<T>>
struct sparse_table {
    vector<vector<T>> sp;
    T get(int l, int r) {
        int k = leqpow[r - l + 1];
        T r1 = sp[k][l], r2 = sp[k][r - (1 << k) + 1];
        return compare()(r1, r2) ? r1 : r2;
    }
    template<class InputIterator>
    sparse_table(InputIterator begin, InputIterator end) {
        int n = end - begin;
        sp.assign(leqpow[n] + 1, vector<T>(n));
        copy(begin, end, sp[0].begin());        
        for (int k = 1, pw = 1; pw + pw <= n; ++k, pw *= 2) 
            for (int i = 0; i + pw < n; ++i) 
                sp[k][i] = compare()(sp[k - 1][i], sp[k - 1][i + pw]) ? sp[k - 1][i] : sp[k - 1][i + pw];
    }
};

int32_t main() {
    
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i] - i;
    }
    sparse_table<int> s(b, b + n);
    ll ans = 0;
    for (int i = n-1; i >= 0; --i) {
        dbg(i);
        if (a[i] > i) no();
        dbg("ok");
        int pos = i - a[i] + 1;
        dbg(pos);
        dbg(s.get(pos, i));
        if (a[i] && s.get(pos, i) < b[i]) no();
        if (a[i] > a[i + 1] - 1) {
            ans += a[i];
        }
    }

    cout << ans << '\n';
    

    return 0;
}


Measured memory_bytes: 17540
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll k;cin>>k;
  ll ans=0;
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        ans+=gcd(i,gcd(j,l));
      }
    }
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3656