akhauriyash/Code-Regression huggingface dataset:
from collections import deque


def bfs(v, N):
    dist = [-1 for _ in range(N)]
    que = deque()
    que.append((v, 0, -1))
    while que:
        (now, cost, par) = que.popleft()
        dist[now] = cost
        for edge in edges[now]:
            if edge == par:
                continue
            que.append((edge, cost + 1, now))
    return dist


N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N - 1):
    a, b = map(int, input().split(' '))
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

dist_from_one = bfs(0, N)
dist_from_N = bfs(N - 1, N)
fennec = 0
for i in range(N):
    fennec += int(dist_from_one[i] <= dist_from_N[i])

print('Fennec' if 2 * fennec > N else 'Snuke')

Measured memory_bytes: 41228
int N[]={ 6,10,18,14,  2,13,22,11,  3, 5,21,19,  1,17,23, 7,  0, 9,20,15,  4,12,16, 8};
int E[]={15, 7,11,19,  8, 3,14,23, 16, 0, 6,22,  4, 2,18,20, 12, 1,10,21,  9, 5,13,17};
int W[]={ 9,17,13, 5, 12,21,10, 1,  4,20,18, 2, 16,22, 6, 0,  8,23,14, 3, 15,19,11, 7};
int S[]={16,12, 4, 8, 20, 9, 0,15, 23,17, 1, 7, 21, 5, 3,19, 22,13, 2,11, 18,10, 6,14};
n,d,a;
char s[9];
main(c)
{
for(;c-48&&scanf("%s",s);)
c=*s,
c<60&&a?printf("%d\n",a),a=0:0,
d=
(c-78?0:N[d])+
(c-69?0:E[d])+
(c-87?0:W[d])+
(c-83?0:S[d])+
(c-82?0:d&28|d%4+1&3)+
(c-76?0:d&28|d%4-1&3),
a+=d/4+1,
d=d%24;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(int argc, char* argv[]) {
  int ab, bc, ca;
  cin >> ab >> bc >> ca;

  cout << ab * bc / 2;

  return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n, a;

int main()
{
    while (cin >> n >> a) {
		cout << n*n - a << endl;
    }
}
















Measured memory_bytes: 256
#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,k;
    cin>>n>>k;

    vector<int> sunuke(n);

    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            sunuke[a-1]++;
        }
    }

    int ans=0;
    rep(i,n){
        if(sunuke[i]==0)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt(), m = sc.nextInt();
        boolean[] direct = new boolean[n + 1];
        int[] x = new int[m], y = new int[m];
        for (int i = 0; i < m; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            if (x[i] == n) direct[y[i]] = true;
            if (y[i] == n) direct[x[i]] = true;
        }

        boolean ok = false;
        for (int i = 0; i < m; i++) {
            ok |= x[i] == 1 && direct[y[i]] || y[i] == 1 && direct[x[i]];
        }

        out.println(ok ? "POSSIBLE" : "IMPOSSIBLE");
        out.flush();
        out.close();
    }

























    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 45212
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 100001;
const int INF = 1000000001;

int n, k;
int a[MAX];

int main(void) {
	// in = fopen("C.in", "rt");
	
	fscanf(in, "%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
	    fscanf(in, "%d", &a[i]);
    }
    sort(a, a + n);
    
    int ans = INF;
    for (int i = k - 1; i < n; i++) {
        ans = min(ans, a[i] - a[i - k + 1]);
    }
    fprintf(out, "%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
Alice = []
Bob = []
for i in range(1,N+1):
    if i % 2 != 0:
        Alice.append(A[i-1])
    else:
        Bob.append(A[i-1])
print(sum(Alice)-sum(Bob))

Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
using namespace std;

int main(int argc, char **argv)
{
    // f(n) = min(f(n-1) + |h_n-1 - h_n|, f(n-2) + {h_n-1 - h_n})
    int N;
    cin >> N;
    int h[N];
    for (int i = 0; i < N; ++i) cin >> h[i];

    int f[N];

    f[0] = 0;
    f[1] = abs(h[0] - h[1]);

    for (int i = 2; i < N; ++i) {
        int cost_1 = f[i - 1] + abs(h[i - 1] - h[i]);
        int cost_2 = f[i - 2] + abs(h[i - 2] - h[i]);
        f[i] = (cost_1 < cost_2)? cost_1 : cost_2;
    }

    cout << f[N - 1];

    return 0;
}


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

int main()
{
	int n;
	int N[51];
	int sum = 0;

	cin >> n;

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

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			sum += N[i] * N[j];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{int n,a,b,s=0,x;
 cin>>n>>a>>b;
 for(int i=1;i<=n;i++)
 {
  int v=0;
 	x=i;
  while(x!=0)
  {
   v+=x%10;
   x=x/10;
  }
  if(v>=a&&v<=b)
  s+=i;
 }
 cout<<s;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main(){
  long int N,M,result=0;
  vector <pair<long int,long int> > v;
  cin>>N>>M;
  for(int i=0;i<N;i++){
    long int a,b;
    cin>>a>>b;
    v.push_back(make_pair(a,b));
  }
  sort(v.begin(),v.end());
  //cout<<endl;
  //for(int i=0;i<N;i++)cout<<v[i].first<<" "<<v[i].second<<endl;
  for(int i=0;i<N;i++){
    //cout<<i<<" "<<M<<" "<<v[i].second<<endl;
    if(M-v[i].second>0){
      result+=v[i].second*v[i].first;
      M-=v[i].second;
    }
    else if(M-v[i].second<=0){
      result+=M*v[i].first;
      break;
    }
  }
  cout<<result<<endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
int main() {
 
  //  cout << 5 * 100000 + 100000 + 5 * 10000 + 10000 + 5 * 1000 + 1000 << endl;
   
  while(1) {
    int P, N[7] = {};
    scanf("%d", &P); if(P == 0) break;
    REP(i, 1, 7) scanf("%d", &N[i]);
 
    int ans = 1000000000;
 
    REP(d, P, P + 100000) {
      int D = d;
       
      int U = 0;
      int k, m;
       
      m = D / 500;
      k = min(m, N[6]);
      D %= 500; D += (m - k) * 500;
      U += k;
       
      m = D / 100;
      k = min(m, N[5]);
      D %= 100; D += (m - k) * 100;
      U += k;
       
      m = D / 50;
      k = min(m, N[4]);
      D %= 50; D += (m - k) * 50;
      U += k;
       
      m = D / 10;
      k = min(m, N[3]);
      D %= 10; D += (m - k) * 10;
      U += k;
       
      m = D / 5;
      k = min(m, N[2]);
      D %= 5; D += (m - k) * 5;
      U += k;
       
      m = D;
      k = min(D, N[1]);
      D += (m - k);
      U += k;
       
      int T = d - P;
      int S = 0;
      S += T / 500; T %= 500;
      S += T / 100; T %= 100;
      S += T / 50; T %= 50;
      S += T / 10; T %= 10;
      S += T / 5; T %= 5;
      S += T;
 
      ans = min(ans, U + S);
    }
    printf("%d\n", ans);
  }
   
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 3; ++i) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

typedef pair < int, int> P;
int N;
string S, T;

int main()
{
	cin >> N;
	cin >> S >> T;
	rep(i, N) {
		cout << S[i] << T[i];
	}
	cout << endl;
	
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

void eratos ( int n, vector<bool>&  prime){
	prime[2] = true; prime[0] = prime[1] = false;
	for(int i = 3; i <= n; i += 2) prime[i] = true, prime[i+1] = false;
	for(int i = 3; i*i <= n ; i += 2) if(prime[i]){
		for(int j = i * i, k = i * 2; j <= n; j += k) prime[j] = false;
	}
}



int main()
{
 
	cin.tie(0); ios_base::sync_with_stdio(false);
	vector<bool> pr(100020);
	eratos(100015, pr);
	
	VI v;
	rep(i,100001) if(i&1 && pr[i]){
		int p = (i +1)/2;
		if(pr[p]) v.push_back(i);
	}
	//rep(i,50) printf("%d, ",v[i]); puts("");
	int q;
	cin >>q;
	
	while(q--){
		int l,r;
		cin >>l >>r;
		
		auto it1 = lower_bound(all(v),l);
		auto it2 = upper_bound(all(v), r);

		cout << it2  - it1  <<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 640
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define pb  push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int> 
#define vpr vector<pr> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
# define pi           3.14159265358979323846
const int mod = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding

	double n;
	cin>>n;
	cout<<setprecision(20)<<2*n*pi<<endl;

	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 3780
import numpy as np
import sys

n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
a = a[a%2==0]

for i, j  in enumerate(a):
    if j%3 != 0 and j%5 != 0:
        print("DENIED")
        sys.exit()

print("APPROVED")

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
signed main(){
	int q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	int t;
		t=min(q*4,h*2);
		t=min(t,s);
	if(t*2<=d){
		cout<<t*n<<endl;
	}
	else{
		int m=(n/2)*d+(n%2)*t;
		cout<<m<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	string s = ReadLine();
	char x = s[0], y = s[2];
	if (x > y)       { WriteLine(">"); }
	else if (x == y) { WriteLine("="); }
	else             { WriteLine("<"); }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;

long long a,b,k;

int main()
{
    scanf("%lld%lld%lld",&a,&b,&k);
    if (a>=k){
        a-=k;
        printf("%lld %lld\n",a,b);return 0;
    }
    k-=a;
    b-=k;
    if (b<0) b=0;
    printf("0 %lld\n",b);

}





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

using namespace std;

#define int ll

typedef long long ll;
typedef pair<int, int> P;

const int inf = 1e9+2;

int N;
vector<int> v;
vector<int> can;
vector<P> pre;

int need(int l, int r, int th) {
	if (r-l == 1) {
		if (v[l] >= 0) {
			return v[l] >= th ? 0 : inf;
		}
		else {
			return 1;
		}
	}
	else {
//		assert( (r - l) % 3 == 0 );
		int d = (r - l) / 3;
		vector<int> a(3);
		for (int i = 0; i < 3; ++i) {
			a[i] = need(l + d * i, l + d * (i+1), th);
		}
		sort(a.begin(), a.end());
		return a[0] + a[1];
	}
}
signed main() {
	int M; cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int D, p; cin >> D >> p; --p;
		pre.push_back( P(D, p) );
	}
	for (int i = 0; i < N-M; ++i) {
		int D; cin >> D;
		pre.push_back( P(D, -1) );
	}

	int tN; for (tN = 1; tN < N; tN *= 3);
	for (int i = 0; i < N; ++i) {
		if (pre[i].second >= 0) {
			pre[i].second += (tN - N) / 2 * 3;
			if (pre[i].second >= tN) {
				pre[i].second = (pre[i].second-tN) * 3 + 2;
			}
		}
	}
	for (int i = 0; i < (tN-N)/2; ++i) {
		pre.push_back( P(0, i*3) );
		pre.push_back( P(inf, i*3+1) );
	}
	sort( pre.begin(), pre.end() );

	N = tN; v = vector<int>(N, -1);
	for (int i = 0; i < (int)pre.size(); ++i) {
		if (pre[i].second >= 0) {
			assert(v[pre[i].second] == -1);
			v[pre[i].second] = pre[i].first;
		}
		else {
			can.push_back(pre[i].first);
		}
	}
	sort(can.begin(), can.end());

	int cnt = 0;
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == -1) ++cnt;
	}
	assert( cnt == can.size() );

	ll l = 1, r = inf;
	for (int t = 0; t < 100; ++t) {
		int m = (l + r) / 2;
		int rest = (int)can.size() - (int)(lower_bound( can.begin(), can.end(), m ) - can.begin());
		if ( need(0, N, m) <= rest ) {
			l = m;
		}
		else {
			r = m;
		}
	}
	assert( r - l <= 1 );
	cout << l << endl;
}

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int d[n][2];
	int c = 0;
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> d[i][0] >> d[i][1];
		if(d[i][0] == d[i][1]){
			c++;
			ans = max(ans,c);
		}else{
			c = 0;
		}
	}
	// keisan
	if(ans >= 3){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll n, m;

ll solve() {
    if (n > m) swap(n, m);

    if (n == 1) {
        if (m == 1) return 1;
        return m - 2;
    } else {
        return (n - 2) * (m - 2);
    }
}

void input() {
    cin >> n >> m;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
import sys
N, M, s, t = map(int, input().split())

from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
    inf = 10**10
    dist = [inf] * N
    Q = [(0, s)]
    decided = set()
    for _ in range(N):
        while True:
            dn, vn = hpp(Q)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, (dn + df, vf))
    return dist
        
        

Edge1 = [[] for _ in range(N)]
Edge2 = [[] for _ in range(N)]
geta = 10**6
for _ in range(M):
    u, v, a, b = map(int, sys.stdin.readline().split())
    u -= 1
    v -= 1
    Edge1[u].append((v, a))
    Edge1[v].append((u, a))
    Edge2[u].append((v, b))
    Edge2[v].append((u, b))

D1 = dijkstra(N, s-1, Edge1)
D2 = dijkstra(N, t-1, Edge2)

D = [d1 + d2 for d1, d2 in zip(D1, D2)]
for i in range(N-2, -1, -1):
   D[i] = min(D[i+1], D[i])

for d in D:
    print(10**15 - d)

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
	string s; cin >> s;
	bool ok = true, t = false;
	if  (s[0] == 'A')
	{
		s[0] = 'a';
		t = true;
	}
	bool h = false;
	for (int i = 2; i < s.length() - 1; ++i)
	{
		if (s[i] == 'C') 
		{
			h = true;
			s[i] = 'c';
			break;
		}

	}
	for (int i = 0; i < s.length(); ++i)
	{
		if (s[i] < 'a' || s[i] > 'z')
		{
			ok = false;
		}
	}
	if (ok && h && t) cout << "AC";
	else cout << "WA";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
ll a[100010],s;
int main()
{
    scanf("%d%d%lld",&n,&k,&s);
    if(s==1)
    {
        for(int i=0;i<k;i++)
        {
            printf("1 ");
        }
        for(int i=k;i<n;i++)
        {
            printf("2 ");
        }
        return 0;
    }
    if(s>n||n==k)
    {
        for(int i=0;i<k;i++)
        {
            printf("%lld ",s);
        }
        for(int i=k;i<n;i++)
        {
            printf("1 ");
        }
        return 0;
    }
    for(int i=0;i<=k;i++)
    {
        if(i%2==0)
        {
            a[i]=1;
        }
        else
        {
            a[i]=s-1;
        }
        printf("%lld ",a[i]);
    }
    for(int i=k+1;i<n;i++)
    {
        printf("%lld ",s+1);
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N, K;
    cin >> N >> K;
    ll H[N+1];
    H[0] = 0;
    rep2(i, 1, N+1) cin >> H[i];
    ll cost[N+1][N+1];
    rep(i, N+1){
        fill_n(cost[i], N+1, INF);
    }
    cost[0][0] = 0;
    ll zero = 0;
    rep2(i, 1, N+1){
        rep2(j, 1, i+1){
            rep(k, i){
                cost[i][j] = min(cost[i][j], cost[k][j-1] + max(zero, H[i]-H[k]));
            }
        }
    }
    ll ans = INF;
    rep(i, N+1) ans = min(ans, cost[i][N-K]);
    cout << ans << endl;
}

Measured memory_bytes: 896
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
ans = 0

for i in range(len(x)-1):
    here = x[i]
    there = x[i+1]
    if (there - here) * a < b:
        ans += (there - here) * a
    else:
        ans += b

print(ans)




Measured memory_bytes: 62704
//  Friendly NUKE is ready!!
#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define dbg(x) cout<<#x<<": "<<x<<endl
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mo 1000000007
#define inf 1e18
#define eps 0.0000000001
#define stp setprecision(20)
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;
//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
 
#define N  int(3010)+10
double  dp[N][N];double p[N];
int main()
{    SPEED;
       int n,x;
       cin>>n;
       loop(i,1,n+1){
       	 cin>>p[i] ;
       }
        dp[0][0] = 1 ;
       loop(i,1,n+1){
       	  
       	   loop(heads,0,i+1){
       	   	 if(heads==0){
       	   	 	 dp[i][heads] = (1-p[i])*dp[i-1][heads] ;continue ;
       	   	 }
       	   	 dp[i][heads] = p[i]*dp[i-1][heads-1]+(1-p[i])*dp[i-1][heads] ;
       	   }
       } double sm =0 ;
       loop(heads,0,n+1){
       	  if(heads>n/2)sm+=dp[n][heads] ;
       } 
       cout<<fixed<<stp<<sm;
}

Measured memory_bytes: 50024
#include <stdio.h>
int solve(int i,int m);

int A[100];
int n;

int main()
{

  int i;
  int m;
  int c;
  int abc;
  
  scanf("%d",&n);
  for( i = 0; i < n ; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&m);
  for( i = 0; i < m ; i++){
    scanf("%d",&abc);
    c = solve(0,abc);
    if(c == 1)  printf("yes\n",c);
    else printf("no\n");

  }

  return 0;
  
}



int solve( int i, int m )
{

  int res;
  
  if( m == 0) return 1;
  if( i >= n) return 0;
  if( res = solve( i + 1, m) || solve( i + 1, m - A[i]))return 1;

    
}





Measured memory_bytes: 2044
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int[] time = new int[n];
    long sum = 0;

    for (int i = 0; i < n; i++) {
      time[i] = sc.nextInt();
    }

    for (int i = 0; i < (n - 1); i++) {
      sum += Math.min(time[i + 1] - time[i], t);
    }

    sum += t;

    System.out.println(sum);

  }
}

Measured memory_bytes: 60208
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        var A = cin.nextString();
        var B = cin.nextString();

        if (A[0] > B[0]) {
            Console.WriteLine(">");
        } else if (A[0] < B[0]) {
            Console.WriteLine("<");
        } else {
            Console.WriteLine("=");
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 13140
///
// File:  0003.cpp
// Author: ymiyamoto
//
// Created on Sat Nov  4 15:48:51 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint32_t N;
  cin >> N;
  for (uint32_t i = 0; i < N; i++) {
    uint32_t a, b, c;
    cin >> a >> b >> c;
    if (a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3012
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <cmath>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int main(){
	ll x, i = 1, now = 0;
	gets(x)
	while(true){
		now += i;
		if (x <= now){
			break;
		}
		i += 1;
	}
	puts(i)
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC088C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] c1 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int[] c2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int[] c3 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int b2 = c2.Sum() - c1.Sum();
            int b3 = c3.Sum() - c1.Sum();
            int a2 = c1[1] + c2[1] + c3[1] - c1[0] - c2[0] - c3[0];
            int a3 = c1[2] + c2[2] + c3[2] - c1[0] - c2[0] - c3[0];

            if (b2 % 3 == 0 && b3 % 3 == 0 && a2 % 3 == 0 && a3 % 3 == 0)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13652
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int res = (X/500)*1000;
        X -=  (X/500)*500;
        res += (X/5)*5;
        System.out.println(res);
    }
}

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

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int r , c , n ; 
vector<pair<pair<int,int>,int> > arr ; 
bool is(int x , int y) {
    return (x == 0 || y == 0 || y == c || x == r) ;
}
void Insert(int x , int y , int idx) { 
    if(x == 0) arr.pb({{1,y},idx}) ; 
    else if(y == c) arr.pb({{2,x},idx}) ;
    else if(x == r) arr.pb({{3,-y},idx}) ;
    else arr.pb({{4,-x},idx}) ;
}
int32_t main()
{
    fast;
    int idx = 1 ;
    cin >> r >> c >> n ; 
    rep(i,1,n) {
        int x1 , y1 , x2 , y2 ; 
        cin >> x1 >> y1 >> x2 >> y2 ; 
        if(is(x1,y1) && is(x2,y2)) {
            Insert(x1,y1,idx) ;
            Insert(x2,y2,idx) ;
            ++idx ; 
        }
    }
    sort(all(arr)) ;
    stack<int> bla ; 
    for(auto it : arr) {
        if(bla.empty() == false && bla.top() == it.second) bla.pop() ;
        else bla.push(it.second) ;
    }
    if(bla.empty()) cout << "YES\n" ; 
    else cout << "NO\n" ;
    return 0;
}



Measured memory_bytes: 8176
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 最速で何番目にゴールできるかを考える
# 自分より左のロボットを1,3,5,…に配置したい
# それが不可能なロボットの個数をカウントしていけば良い

N = I()
x = LI()

remove = [False]*N
place = 1
for i in range(N):
    if x[i] < place:
        remove[i] = True
    else:
        place += 2

first_goal = [1]*N
for i in range(1,N):
    if remove[i-1]:
        first_goal[i] = first_goal[i-1]+1
    else:
        first_goal[i] = first_goal[i-1]

d = defaultdict(int)
for i in range(N):
    d[first_goal[i]] += 1

dc = [0]*(N+1)
for i in range(1,N+1):
    dc[i] = dc[i-1]+d[i]

ans = 1
for i in range(1,N+1):
    ans *= dc[i]-(i-1)
    ans %= mod

print(ans)

Measured memory_bytes: 66344
var fs = require('fs');
var s = fs.readFileSync('/dev/stdin', 'utf8');
var a = 0;

for (var i = 0; i < s.length; ++i) {
  if (s[i] === '+') {
    ++a;
  } else if (s[i] === '-') {
    --a;
  }
}

console.log(a);


Measured memory_bytes: 7624
#include<stdio.h>
#define MAX_N 100
#define MAX_M 10000
#define MAX_D 200
#define MAX_C 20
#define MAX_AREA 50
#define MAX_Q 10000
#define MAX_R 100
#define INF 1000000000
int n, m, nc, s, g;
int p[MAX_C],q[MAX_C][MAX_AREA],r[MAX_C][MAX_AREA],sc[MAX_C][MAX_AREA];
int dist[MAX_C][MAX_N][MAX_N];
void wf(int c){
    int i,j,k;
    for(k=0;k<n;k++){
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(dist[c][i][j]>dist[c][i][k]+dist[c][k][j])
                    dist[c][i][j]=dist[c][i][k]+dist[c][k][j];
            }
        }
    }
}
int cost(int c,int d){
    int i,uc=0;
    if(d==0) return 0;
    if(d==INF) return INF;
    for(i=p[c]-1;i>=0;i--){
        if(d>q[c][i]) break;
    }
    return sc[c][i]+(d-q[c][i])*r[c][i];
}
void dtoc(int c){
    int i,j,d;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            dist[c][i][j]=cost(c,dist[c][i][j]);
}
void solve(){
    int i,j,c;
    for(i=0;i<nc;i++){
        wf(i);
        dtoc(i);
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            for(c=1;c<nc;c++){
                if(dist[c][i][j]<dist[0][i][j])
                    dist[0][i][j]=dist[c][i][j];
            }
        }
    }
    wf(0);
    if(dist[0][s-1][g-1]==INF)
        printf("-1\n");
    else
        printf("%d\n",dist[0][s-1][g-1]);
}
void init(){
    int i,j,k;
    for(i=0;i<MAX_C;i++){
        p[i]=0;
        for(j=0;j<MAX_AREA;j++)
            q[i][j]=r[i][j]=0;
    }
    for(i=0;i<MAX_C;i++){
        for(j=0;j<MAX_N;j++){
            for(k=j;k<MAX_N;k++){
                if(j==k) dist[i][j][k]=0;
                else dist[i][j][k]=dist[i][k][j]=INF;
            }
        }
    }
}
int main(void){
    int i,j;
    int x,y,d,c;
    while(1){
        scanf("%d%d%d%d%d",&n,&m,&nc,&s,&g);
        if(n==0&&m==0&&nc==0&&s==0&&g==0) break;
        init();
        for(i=0;i<m;i++){
            scanf("%d%d%d%d",&x,&y,&d,&c);
            if(dist[c-1][x-1][y-1]>d)
                dist[c-1][x-1][y-1]=dist[c-1][y-1][x-1]=d;
        }
        for(i=0;i<nc;i++)
            scanf("%d",&p[i]);
        for(i=0;i<nc;i++){
            for(j=1;j<p[i];j++)
                scanf("%d",&q[i][j]);
            q[i][0]=0;
            for(j=0;j<p[i];j++)
                scanf("%d",&r[i][j]);
            sc[i][0]=0;
            for(j=1;j<p[i];j++)
                sc[i][j]=sc[i][j-1]+(q[i][j]-q[i][j-1])*r[i][j-1];
        }
        solve();
    }
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H+2);
  for (int i=1; i<H+1; i++) cin >> S[i];

  // banpei
  for (int i=0; i<W+2; i++) {
    S[0][i] = '.';
    S[H+1][i] = '.';
  }
  for (int i=1; i<H+1; i++) {
    S[i] = "." + S[i] + ".";
  }

  string ans = "Yes";
  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++) {
      if (S[i][j] == '#') {
        if (S[i-1][j] != '#' && S[i+1][j] != '#' && S[i][j-1] != '#' && S[i][j+1] != '#')
          ans = "No";
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    public static class Node {
        private int counter;
        private List<Integer> children;

        public Node() {
            this.children = new ArrayList<>();
        }

        public void addChild(int child) {
            this.children.add(child);
        }
    }

    private static void solve() {
        int n = in.nextInt();
        int q = in.nextInt();

        Node[] nodes = new Node[n];
        for (int i=0; i < n; i++)
            nodes[i] = new Node();

        for (int i=0; i < n-1; i++) {
            int a = in.nextInt();
            int b = in.nextInt();

            nodes[a - 1].addChild(b - 1);
            nodes[b - 1].addChild(a - 1);
        }

        for (int i=0; i < q; i++) {
            int p = in.nextInt();
            int x = in.nextInt();
            nodes[p - 1].counter += x;
        }

        boolean[] visited = new boolean[n];
        Queue<Integer> toVisit = new ArrayDeque<>();
        visited[0] = true;
        toVisit.add(0);
        while (!toVisit.isEmpty()) {
            int i = toVisit.poll();
            Node p = nodes[i];
            List<Integer> toAdd = p.children;
            for (int a : toAdd) {
                if (!visited[a]) {
                    visited[a] = true;
                    toVisit.add(a);
                    nodes[a].counter += p.counter;
                }
            }
        }
        

        // dfs(nodes, -1, 0);

        out.println(
                Arrays.stream(nodes).map(p -> String.valueOf(p.counter)).collect(Collectors.joining(" "))
        );
    }

    private static void dfs(Node[] nodes, int parent, int index) {
        if (parent >= 0) {
            nodes[index].counter += nodes[parent].counter;
        }

        for (int child : nodes[index].children) {
            if (child != parent)
                dfs(nodes, index, child);
        }
    }

}


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

typedef pair<int,int> PAIR;
const int INF=100000000;
 
int main(){
	string s;
	cin>>s;
	int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
	if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
	else if(a-b-c+d==7)cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
	else if(a-b+c-d==7)cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
	else if(a-b+c+d==7)cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
	else if(a+b-c-d==7)cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
	else if(a+b-c+d==7)cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
	else if(a+b+c-d==7)cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
	else if(a+b+c+d==7)cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 5005;

int dp[MAX_N][MAX_N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	string s;
	cin >> s;
	int l = 0, r = s.length() - 1;
	int ans = 0;
	while(l < r){
		if(s[l] != s[r]){
			ans++;
		}
		l++;
		r--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
total = (pow(2, n, mod) - 1) % mod

def fast_nCr(n, r):
    upper = 1
    for i in range(n - r + 1, n + 1):
        upper = upper * i % mod
    below = 1
    for i in range(1, r + 1):
        below = below * i % mod
    ans = upper * pow(below, mod - 2, mod) % mod
    return ans % mod

A = fast_nCr(n, a)
B = fast_nCr(n, b)
ans = (total - A - B) % mod
print(ans)

Measured memory_bytes: 38896
#include <iostream>
#include <vector>
using namespace std;
int main()
{
        int h,n,sum = 0;
        cin >> h >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
        {   
                cin >> a[i];
                sum += a[i];
        }   
        if (sum >= h)
                cout << "Yes";
        else
                cout << "No";
        cout << endl;
        return 0;
}

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

using namespace std;

#define mod 1000000007
#define NMAX 2000

vector<vector<long long>> C(NMAX + 1, vector<long long>(NMAX + 1));

void CalcC(){
	for (int i = 0; i < NMAX+1; i++){
		for (int j = 0; j <= i; j++){
			int a = 1;
			if (j == 0 || i == j)
				C[i][j] = 1;
			else
				C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}
}

int main(){
	int N, K;
	cin >> N >> K;

	CalcC();
	for (int i = 1; i <= K; i++){
		cout << (C[N - K + 1][i] * C[K - 1][i - 1]) % mod << endl;
	}
}

Measured memory_bytes: 31616
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] s = new long[n];
        for(int i = 0; i < n; i++){
            s[i] = sc.nextLong();
        }
        int q = sc.nextInt();
        long[] t = new long[q];
        for(int i = 0; i < q; i++){
            t[i] = sc.nextLong();
        }
        Arrays.sort(s);
        int ans = 0;
        for(int i = 0; i < q; i++){
            for(int j = 0; j < n; j++){
                if(s[j] == t[i]){
                    ans++;
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 39724
object Main extends App {
	val Array(x1, y1, x2, y2) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	
	val x3 = x2 + y1 - y2 
	val y3 = y2 + x2 - x1

	val x4 = x1 + y1 - y2
	val y4 = y1 + x2 - x1

	println(x3 + " " + y3 + " " + x4 + " " + y4)
}

Measured memory_bytes: 27344
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<vector<int>,vector<bool> > > v;
		for(int t = 0; t < n + 1; t++) {
			vector<int> len;
			vector<bool> g;
			int x, y;
			int m;
			cin >> m;
			cin >> x >> y;
			pair<int,int> prev0, prev1;
			prev0.first = x; prev0.second = y;
			for(int i = 1; i < m; i++) {
				cin >> x >> y;
				len.push_back(fabs(x - prev0.first + y - prev0.second));
				if(i > 1) {
					int x_, y_;
					x_ = x - prev0.first;
					y_ = y - prev0.second;
					bool push;
					push = prev1.first * y_ - prev1.second * x_ > 0;
					g.push_back(push);
							
				}
				prev1.first = x - prev0.first;
				prev1.second = y - prev0.second;
				prev0.first = x;
				prev0.second = y;
			}
			v.push_back(pair<vector<int>, vector<bool> >(len, g));
		}
		
		for(int i = 1; i < v.size(); i++) {
			if(v[i].first.size() != v[0].first.size())
				continue;
			bool flag0, flag1;
			flag0 = flag1 = true;
			for(int j = 0; j < v[i].first.size(); j++) {
				if(v[0].first[j] != v[i].first[j])
					flag0 = false;
				if(v[0].first[j] != v[i].first[v[i].first.size() - 1 - j])
					flag1 = false;
			}

			if(!(flag0 | flag1))
				continue;
			bool flag00, flag01;
			bool flag10, flag11;

			/*
			flag00 = v[0].second[0];
			flag10 = v[0].second[v[0].second.size() - 1];

			flag01 = !flag00;
			flag11 = !flag10;
			*/
			flag00 = flag11 = true;
			flag01 = flag10 = false;

			for(int j = 0; j < v[0].second.size(); j++) {
				if(flag0) {
					flag00 &= !(v[0].second[j] ^ v[i].second[j]);
					flag01 &= !(!v[0].second[j] ^ v[i].second[j]);
				}
				if(flag1) {
					flag10 &= !(v[0].second[j] ^ v[i].second[v[0].second.size() - 1 - j]);
					flag11 &= !(!v[0].second[j] ^ v[i].second[v[0].second.size() - 1 - j]);
				}
			}

			if((flag0 && flag00) || (flag0 && flag01) || (flag1 && flag10) || (flag1 && flag11)) {
				cout << i << endl;
			}
		}
		cout << "+++++" << endl;
	}
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
long long n,b,s,t,i,j;
main(){  
  cin>>n;
  int a[n];
  for(;i-n;s+=a[i++])cin>>a[i];
  b=1e15;
  for(;j-n+1;)t+=a[j++],b=min(b,abs(2*t-s));
  cout<<b<<endl;
}


Measured memory_bytes: 1024