akhauriyash/Code-Regression huggingface dataset:
import numpy as np

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for _ in range(N)])

# print(X)
d = []

for i in range(N - 1):
    for j in range(i + 1, N):
        d.append((sum((X[j] - X[i]) ** 2)) ** 0.5)
d = np.array(d)
# print(d)
np.mod(d, 1, out=d)
mask = d == 0


# print(mask)
print(np.count_nonzero(mask))


Measured memory_bytes: 12532
def bubble_sort(l):
    num = 0
    for index in range(len(l)):
        for low in range(len(l)-1, index, -1):
            if l[low] < l[low-1]:
                l[low], l[low-1] = l[low-1], l[low]
                num += 1

    return (l, num)
if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))
    lsorted, num = bubble_sort(l)
    print(" ".join(list(map(str,lsorted))))
    print(num)


Measured memory_bytes: 5604
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
//#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int i, j, h, w, s;
	while (fscanf(stdin, "%d%d", &h, &w), h || w) {
		s = h*h + w*w;
		i = h + 1;
		while (1) {
			for (; i*i < s; i++) {
				for (j = i + 1; j*j + i*i <= s; j++)
					if (i*i + j*j == s) goto e;
			}
			s++, i = 1;
		}
		e:
		fprintf(stdout, "%d %d\n", i, j);
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int n; cin >>n;
  vector<int> a(n); rep(i, n) cin >>a.at(i);
  map<int,int> left, right;
  int res = 0;
  vector<int> k(n, -1);
  int lefts = 0, rights = 0;
  rep(i, n){
    int x = a[i], y = a[n-1-i];
    if (x != y){
      if (right[x] > 0){
        right[x]--;
        if (right[x] == 0) rights--;
      }else{
        left[x]++;
        if (left[x] == 1) lefts++;
      }
      if (left[y] > 0){
        left[y]--;
        if (left[y] == 0) lefts--;
      }else{
        right[y]++;
        if (right[y] == 1) rights++;
      }
    }
    if (lefts == 0 && rights == 0){
      k[res] = i+1; res++;
    }
  }
  rep(i, res){
    cout <<k[i];
    if (i < res-1) cout <<" ";
  }
  cout <<endl;
}



Measured memory_bytes: 8364
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mincost(vector<ll> v,ll n,ll k)
{
  ll dp[100001];
  dp[0] = 0;
  for(ll i=1;i<k;i++)
    dp[i] = abs(v[i] - v[0]);
  for(ll i=k;i<n;i++)
  {
    dp[i] = INT_MAX;
    for(ll j=i-1;j>=i-k;j--)
    dp[i] = min(dp[j] + abs(v[i] - v[j]),dp[i]);
  }
  return dp[n-1];
}
int main()
{
  vector<ll> v;
  ll n,t,k;
  cin>>n>>k;
  for(ll i=0;i<n;i++)
  {
    cin>>t;
    v.push_back(t);
  }
  cout<<mincost(v,n,k);

  return 0;
}

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

namespace AtCoderBeginnerContest148
{
	class Program
	{
		static void Main(string[] args)
		{
			var numbers = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
			var bigNumber = numbers.Max();
			var smallNumber = numbers.Min();

			var primes = PrimeFactors(smallNumber).ToList();

			long result = bigNumber;
			if((result / smallNumber) * smallNumber == bigNumber)
			{
				Console.WriteLine(bigNumber);
				return;
			}

			result = (long)smallNumber * (long)bigNumber;
			for (var i = 0; i < primes.Count; i++)
			{
				var tmp = result / primes[i];
				if(tmp * primes[i] != result)
				{
					continue;
				}

				if((tmp / smallNumber) * smallNumber == tmp)
				{
					result = tmp;
				}
			}
			Console.WriteLine(result);
		}

		public static IEnumerable<int> PrimeFactors(int n)
		{
			int i = 2;
			int tmp = n;

			while (i * i <= n) //※1
			{
				if (tmp % i == 0)
				{
					tmp /= i;
					yield return i;
				}
				else
				{
					i++;
				}
			}
			if (tmp != 1) yield return tmp;//最後の素数も返す
		}
	}
}


Measured memory_bytes: 13268
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();

		int deka=Math.max(N,M);
		int mini=Math.min(N,M);

		long kotae1=1;
		long kotae2=1;
		if(deka==mini) {
			kotae1=Kaijyo_mod(deka,1000000007);
			System.out.println((kotae1*kotae1*2)%1000000007);
		}
		else if(deka-1==mini) {
			kotae1=Kaijyo_mod(deka,1000000007);
			kotae2=Kaijyo_mod(mini,1000000007);
			System.out.println((kotae1*kotae2)%1000000007);
		}
		else {
			System.out.println(0);
		}
	}

	public static long Kaijyo_mod(int n,int mod) {
		long aa=1;

		for(int i=n; i>=2; i--) {
			aa*=i;
			aa=aa%mod;
		}
		return aa;
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;

    if((n+1)/2 >= k)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  long long a;
  long long sum[200005] = {};
  long long ans = 0;

  cin >> n;
 
  for(int i = 1;i <= n;i++){
    cin >> a;
    sum[i] = sum[i - 1] + a;
  }
 
  sort(sum, sum + n + 1);

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




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

bool includes3(int x) {
    do {
        if (x % 10 == 3)
            return true;
        x /= 10;
    } while (x > 0);
    return false;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || includes3(i)) {
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}



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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



  //二分探索(最小値を出す問題は疑う)


// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < N; ++i){
// 		res += max(0ll, A[i]-x/F[i]);
//     }
//     return res <= K;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }

int main(){
  string S;
  cin >> S;
  ll kaisuu;
  cin >> kaisuu;
  vector<ll>ren;
  
  
  REP(i, S.size()){
    ll k = 0;
    while(i + k < S.size() && S.at(i) == S.at(i + k))  k++;
    ren.push_back(k);
    i += k - 1;
  }
// REP(i, ren.size()) print(ren.at(i));
  ll ans = 0;
  if(ren.size() == 1) ans = ren.at(0) * kaisuu / 2;
  else if(S.at(0) != S.at(S.size()- 1)) {
    REP(i, ren.size()) ans += ren.at(i) / 2;
    ans *= kaisuu;
  }else{
    for(int i = 1; i < ren.size() - 1; i++) ans += ren.at(i) / 2;
    ans *= kaisuu;
    ans += ren.at(0) / 2 + ren.at(ren.size() - 1) / 2;
    ans += ((ren.at(0) + ren.at(ren.size() - 1)) / 2) * (kaisuu - 1);
  }

print(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll a , b , c , x , y;
    cin >> a >> b >> c >> x >> y;
    ll mab = 2 * c;
    ll aab = a + b;
    if(mab <= aab)
    {
        ll foo = 0 ;
        foo = foo + mab * min(x , y);
        ll rem = max(x , y) -  min(x , y) ;
        if(x < y){
            ll ekkaniraj = min(b , 2*c);
            foo = foo + ekkaniraj * rem;
            cout << foo << el ;
            ro ;
        }
        else if(x > y){
            ll ekkaniraj = min(a , 2*c);
            foo = foo + ekkaniraj * rem ;
            cout << foo << el ;
            ro ;
        }
        else {
            cout << foo << el ;
            ro ;
        }
     }
     else if(mab > aab)
     {

         ll foo = 0 ;
         foo = aab * min(x , y) ;
         ll rem = max(x , y) - min(x , y) ;
         if(x < y){
            ll ekkaniraj = min(b , 2*c) ;
            foo = foo + ekkaniraj * rem ;
            cout << foo << el ;
            ro ;
         }
         else if(x > y ){
            ll ekkaniraj = min(a , 2*c) ;
            foo = foo + ekkaniraj * rem ;
            cout << foo << el;
            ro ;
         }
         else cout << foo << el ;
         ro ;
     }
     ro ;
}































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

ll GCD(ll a, ll b) {
    if (a % b == 0) {
        return b;
    } else {
        return GCD(b, a % b);
    }
}

ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

void vector_LCM(vector<ll> v) {
    if (v.size() == 1) {
        cout << v[0] << endl;
    } else {
        ll a, b;
        a = v[v.size() - 1];
        v.pop_back();
        b = v[v.size() - 1];
        v.pop_back();
        v.push_back(LCM(a, b));
        vector_LCM(v);
    }
}

int main() {
    int N;
    cin >> N;
    vector<ll> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }

    vector_LCM(T);

    return 0;
}


Measured memory_bytes: 256
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def digits_sum(x: int) -> int:
    result = 0
    while x != 0:
        result += x % 10
        x //= 10
    return result


def main() -> None:
    n = next_int()
    ans = sys.maxsize

    for a in range(1, n):
        b = n - a
        ans = min(ans, digits_sum(a) + digits_sum(b))

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint H, N; cin >> H >> N;
    vec<plint> magic_list(N);
    range(i, 0, N) {
        lint A, B; cin >> A >> B;
        magic_list.at(i) = {A, B};
    }
    const lint offset = 1e4;
    vec<lint> dp(H + 1 + offset, 1LL << 58);
    dp.at(H + offset) = 0;
    range(i, 0, N) {
        lint atk, mp;
        tie(atk, mp) = magic_list.at(i);
        reversed_range(h, 0, H + offset + 1 - atk) {
            dp.at(h) = min(dp.at(h + atk) + mp, dp.at(h));
        }
    }
    lint res = 1LL << 58;
    range(h, 0, offset + 1) res = min(res, dp.at(h));
    cout << res << '\n';
}

Measured memory_bytes: 384
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	vector<int> vv;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		vv.push_back(x);
	}
	vector<int> ans;
	while (vv.size() > 0) {
		int fl = 0;
		for (int i = vv.size() - 1; i >= 0; --i) {
			if (vv[i] == i + 1) {
				ans.push_back(vv[i]);
				vv.erase(vv.begin() + i);
				fl = 1;
				break;
			}
		}
		if (!fl) {
			cout << -1 << "\n";
			return 0;
		}
	}
	reverse(ALL(ans));
	for (int i: ans)
		cout << i << "\n";
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll int nf[2000001];
ll int inv[2000001];
int main(){
	//ios_base::sync_with_stdio(0); cin.tie(0);
	ll int N=1000000;
	nf[0]=1; nf[1]=1;
	for(ll int i=2;i<=N;i++)
		nf[i]=(nf[i-1]*i)%MOD;
	ll int k=1000000005,invN=1,now=nf[N];
	for(ll int i=0;i<=30;i++){
		if(k&(1<<i)){
			k-=(k&(1<<i));
			invN=(invN*now)%MOD;
		}
		now=(now*now)%MOD;
	}
	inv[N]=invN;
	for(ll int i=N-1;i>=1;i--){
		inv[i]=((i+1)*inv[i+1])%MOD;
	}
	inv[0]=1;
	ll int X,Y,U,R;
	cin>>X>>Y;
	if((X+Y)%3 || 2*Y<X || 2*X<Y){
		cout<<0; return 0;
	}
	U=(2*Y-X)/3; R=(2*X-Y)/3;
	cout<<(((nf[U+R]*inv[U])%MOD)*inv[R])%MOD;
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,x; cin >> n >> x;
    vector<ll> a(n+1, 0);
    rep(i,n) cin >> a[i+1];
    ll ans = 0;
    rep(i,n){
        if(a[i] + a[i+1] > x){
            ans += a[i] + a[i+1] - x;
            a[i+1] = x - a[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    cin.sync_with_stdio(false);

    int n, v[100001];
    long long c, x[100001];

    cin >> n >> c;

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

    long long left[100001], right[100001], maxleft[100001], maxright[100001];

    right[0] = 0; maxright[0] = 0;
    left[0]  = 0; maxleft[0]  = 0;
    right[1] = v[0] - x[0];
    left[1]  = v[n-1] - (c - x[n-1]);
    maxright[1] = max(maxright[0], right[1]);
    maxleft[1] = max(maxleft[0], left[1]);
    for (int i = 2; i <= n; i++) {
        right[i] = right[i-1] + v[i-1] - (x[i-1]   - x[i-1-1]);
        left[i]  = left[i-1]  + v[n-i] - (x[n-i+1] - x[n-i-1+1]);
        maxright[i] = max(maxright[i-1], right[i]);
        maxleft[i] = max(maxleft[i-1], left[i]);
    }

    long long maximum = 0;
    for (int i = 1; i <= n; i++) {

        long long only_right = right[i];
        long long only_left  = left[i];

        long long right_then_left = right[i] - x[i-1] + maxleft[n - i];
        long long left_then_right = left[i] - (c - x[n-i]) + maxright[n - i];

        maximum = max(maximum, max(max(only_left, only_right), max(left_then_right, right_then_left)));
    }

    cout << maximum << endl;

    return 0;
}


Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;

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; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long 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 digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    int sum = 0;
    rep(i, m) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum <= n) {
        cout << n - sum << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}


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

int main(){
  int n,ans=0;string s;cin>>n>>s;
  REP(i,1000){
    stringstream ss;
    ss<<setw(3)<<setfill('0')<<i;
    string t=ss.str();
    int now=0;
    REP(j,n){
      if(t.at(now)==s.at(j)) now++;
      if(now==3){
        ans++;
        break;
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		boolean ans = false;
		for(int a=0;a<=n;a++) {
			for(int b=0;b<=m;b++) {
				if ((n - a) * b + (m - b) * a == k) {
					ans = true;
				}
			}
		}
		System.out.println(ans ? "Yes" : "No");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    vector<vector<ll>> map(h, vector<ll>(w, 0));
    REP(i, b){
        REP(j, a){
            map.at(i).at(j) = 1;
        }
    }
    for(ll i = b; i < h; ++i){
        for(ll j = a; j < w; ++j){
            map.at(i).at(j) = 1;
        }
    }

    REP(i, h){
        ll n1 = 0;
        REP(j, w){
            n1 += map.at(i).at(j);
        }
        if(min(n1, w - n1) != a){
            cout << "No" << endl;
        }
    }
    REP(j, w){
        ll n1 = 0;
        REP(i, h){
            n1 += map.at(i).at(j);
        }
        if(min(n1, h - n1) != b){
            cout << "No" << endl;
        }
    }

    REP(i, h){
        REP(j, w){
            cout << map.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  vector<vector<ll>>a(h,vector<ll>(w));
  ll geta=12800,sz=geta*2+7;
  vector<vector<vector<bool>>>dp(h,vector<vector<bool>>(w,vector<bool>(sz)));
  auto tdp=dp;
  auto b=a;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h)rep(j,w)cin>>b[i][j];
  auto isin=[&](ll y,ll x){
    if(y>=0&&y<h&&x>=0&&x<w)return 1;
    return 0;
  };
  ll d=abs(a[0][0]-b[0][0]);

  dp[0][0][geta-d]=1;
  dp[0][0][geta+d]=1;

  rep(i,h)rep(j,w){
    if(i==0&&j==0)continue;
    ll d=abs(a[i][j]-b[i][j]);
    if(isin(i-1,j)){
      rep(k,sz){
        if(dp[i-1][j][k]==1){
          dp[i][j][k-d]=1;
          dp[i][j][k+d]=1;
        }
      }
    }
    if(isin(i,j-1)){
      rep(k,sz){
        if(dp[i][j-1][k]){
          dp[i][j][k-d]=1;
          dp[i][j][k+d]=1;
        }
      }
    }
  }
  ll res=1e9+7;
  rep(i,sz){
    if(dp[h-1][w-1][i])chmin(res,abs(i-geta));
  }
  cout<<res<<endl;



  return 0;

}


Measured memory_bytes: 42624
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n=r()
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)


Measured memory_bytes: 70984
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
      int B = scanner.nextInt();
      
      int a =A-B*2;
      
      if(B*2>=A){
      System.out.println(0);
      }
      else{
       System.out.println(a);
      }
    }
 }

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar (char ch){
	if	   (ch=='A')return 1;
	else if(ch=='C')return 2;
	else if(ch=='G')return 3;
	else if(ch=='T')return 4;
	else return 0;
} 

long long getKey(char str[]){
	long long sum=0,p=1,i;
	for(int i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
} 

int h1(int x){
	return x%M;
}
int h2(int x){
	return 1+(x%(M-1));
}

int find(char str[]){
	long long x,i,h;
	x=getKey(str);
	for(i=0;;i++){
		h=(h1(x)+i*h2(x))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}

int insert(char str[]){
	long long x,i,h;
	x=getKey(str);
	for(i=0;;i++){
		h=(h1(x)+i*h2(x))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0) {
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i,n,h;
	char str[L],com[9];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",com,str);
		
		if(com[0]=='i'){
			insert(str);
		}
		else {
			if(find(str))printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}



Measured memory_bytes: 15984
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,T;std::cin>>n>>T;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    lint ans=0;
    for(lint i=0;i<n-1;i++){
        ans+=std::min(T,a.at(i+1)-a.at(i));
    }
    ans+=T;
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 1792
// Last Change: 03/31/2019 20:48:03.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  ll ans = INT64_MAX;
  ll tmpAns, tmpN;

  for (ll i = 1; i <= K; ++i) {
    tmpAns = 1;
    tmpN = N - i;

    tmpAns += tmpN / (K - 1);
    tmpAns += (tmpN % (K - 1) > 0 ? 1 : 0);

    ans = min(ans, tmpAns);
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
n, round = gets.split(' ').map(&:to_i)
queue = (0..n-1).map { q = gets.split(' '); [q[0], q[1].to_i] }.to_h

roundtime = 0
finishes = {}

while queue.size != 0 do
  q = queue.shift
  if q[1] <= round
    roundtime += q[1]
    finishes.store(q[0], roundtime)
  else
    roundtime += round
    queue.store(q[0], q[1] - round)
  end
end

finishes.each { |k, v| puts "#{k} #{v}" }


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

int main(){
  int n;cin>>n;
  ll z=0;
  map<pll, pi> m;
  rep(i, n){
    ll x,y;cin>>x>>y;
    if(x==0 && y==0){ z++; continue; }
    ll g = gcd(x, y);
    x /= g; y /= g;
    // rotation 180
    if(y<0){ x *= -1; y *= -1; }
    if(y==0 && x<0){ x *= -1; y *= -1; }
    // rotation 90 in x<0
    bool rot90 = (x<=0);
    if(rot90){
      ll tmp = x;
      x = y; y = -tmp;
//      swap(x, y); 
//      y*=-1;
    }
    if(rot90)m[{x,y}].first++;
    else m[{x,y}].second++;
  }
  ll result = 1;
  for(auto pp: m){
    ll l = pp.second.first, r = pp.second.second;
    l = modpow(2LL, (ll)l, MOD)-1;
//cout<<l<<' '<<r<<endl;
    r =modpow(2LL, (ll)r, MOD)-1;
    result *= (l+r+1)%MOD;
    result %= MOD;
  }

  result = (result-1+MOD)%MOD;
  result = (result+z)%MOD;

  cout<<result<<endl;

  return 0;
}

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

int main(){
    bool cards[4][14];
    int n, rank;
    char suit;
    
    for (int s = 0; s <4; s++)
        for (int r = 1; r <= 13; r++)
            cards[s][r] = 0;
            
    
    cin >> n;
    for (int i = 0; i<n; i++){
        cin >> suit >> rank;
        if (suit == 'S') cards[0][rank] = 1;
        if (suit == 'H') cards[1][rank] = 1;
        if (suit == 'C') cards[2][rank] = 1;
        if (suit == 'D') cards[3][rank] = 1;
        
    }
    
    for (int s = 0; s < 4; s++){
        for (int r = 1; r <= 13; r++){
            if (cards[s][r])continue;
            if (s==0) suit = 'S';
            if (s==1) suit = 'H';
            if (s==2) suit = 'C';
            if (s==3) suit = 'D';
            cout << suit << " " << r << endl;
            
        }
    }
    
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  string s;
  int cnt[26] = {0};
  cin >> s;
  REP(i,s.size()){
    cnt[s[i] - 'a']++;
  }
  REP(i,26){
    if(cnt[i]==0){
      cout << char('a'+i) << endl;
      exit(0);
    }
  }
  cout << "None" << endl;

}




Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  string s;
  cin>>s;
  int c = 0;
  for(int i=0;i<s.size();i++)if(s[i]=='o')c++;
  c+=15-s.size();
  if(c>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
#define pb 					push_back
#define FAST_IO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<"\n";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, set<T> input) {
	for(auto t: input)
		os << t <<"\n";
	return os;
}
multiset<long long> A, B;
int main() {
	//FAST_IO;
  	int X, Y, a, b,c;
  cin >> X >> Y >> a >> b >> c;
  for(int i=1; i<=a; i++) {
    int x;
    cin >> x;
    A.insert(x);
}
    for(int i=1; i<=b; i++) {
    int x;
    cin >> x;
    B.insert(x);
}
    multiset<long long> ans;
    for(int i=1; i<=c; i++) {
    int x;
    cin >> x;
    ans.insert(x);
}

  for(int i=1; i<=X; i++) {
  	long long  x = *(--A.end());
    A.erase(--A.end());
    ans.insert(x);
  }
  for(int i=1; i<=Y; i++) {
  	long long  x = *(--B.end());
    B.erase(--B.end());
    ans.insert(x);
  }
  long long sum =0;
  for(int i=1; i<=X + Y; i++) {
    long long  x = *--ans.end();
    ans.erase(--ans.end());
    sum += x;
  }
  cout << sum << "\n";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) { cin >> p[i]; }
  vector<int> q(n);
  rep(i, n) { cin >> q[i]; }
  vector<int> a(n);
  rep(i, n) { a[i] = i + 1; }

  int cnt = 1;
  int p_i, q_i;
  do {
    int i;
    for (i = 0; i < n; i++) {
      if (p[i] != a[i]) break;
    }
    if (i == n) p_i = cnt;
    for (i = 0; i < n; i++) {
      if (q[i] != a[i]) break;
    }
    if (i == n) q_i = cnt;
    cnt++;
  } while (next_permutation(a.begin(), a.end()));
  cout << abs(p_i - q_i) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <sstream>
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[])
{
    string str;
    string codefestival = "CODEFESTIVAL2016";
    std::cin >> str;
    int c = 0;
    for (int i = 0; i < 16; i++) {
        if (str[i] != codefestival[i]) c++;
    }
    std::cout << c << '\n';
    return 0;
}

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

#define ll long long
#define endl "\n"

using namespace std;

int main() {
    int n;
    cin >> n;
    ll a[n], ans = 0;
    for (int i = 0; i < n; ++ i) {
            cin >> a[i];
        if (i) {
            ans += max(0ll, a[i - 1] - a[i]);
    a[i] = max(a[i], a[i - 1]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 5152
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		Long[] list = new Long[n];
		for(int i = 0; i < n; i++){
		    list[i] = sc.nextLong();
		}
		Arrays.sort(list, Comparator.reverseOrder());
		
		// 計算
		long result = 0;
		for(int i = 1; i < n; i++){
		    result += list[i/2];
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 54876
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int N,M;cin >> N >>M;
    vector<int> foods(M);
    rep(i,N){
        int K;
        cin >> K;
        rep(i,K){
            int a;
            cin >> a;
            a--;
            foods[a]++;
        }
    }
    int res = 0;
    rep(i,M)if(foods[i]==N)res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(N);
  REP(i, M){
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    graph[l].emplace_back(r, d);
    graph[r].emplace_back(l, -d);
  }

  bool ans = true;
  vector<int> dist(N, INF);
  REP(i, N){
    if(dist[i] != INF) continue;
    queue<int> q;
    q.push(i);
    dist[i] = 0;
    while(!q.empty()){
      int p = q.front(); q.pop();
      for(auto v : graph[p]){
        if(dist[v.first] == INF){
          dist[v.first] = dist[p]+v.second;
          q.push(v.first);
        }else{
          if(dist[v.first]-v.second != dist[p]) ans = false;
        }
      }
    }
  }
  ans? Yes: No;

  return 0;
}

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

int main() {
    int n;
    string colors;
    scanf("%d", &n);
    cin >> colors;
    int l = 0;
    int r = n-1;
    int count = 0;

    while(l < r) {
        while(colors[l] != 'W' && l < r) l++;
        while(colors[r] != 'R' && l < r) r--;
        if(l < r) {
            l++; r--; count++;
        }
    }
    cout << count << '\n';
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

struct UnionFind {
    vector<int> par;

    UnionFind(int N): par(N) {
        for (int i=0;i<N;++i) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);

        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);

        return rx == ry;
    }
};


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

    vector<int> P(N);
    rep(i, N) cin >> P.at(i);

    UnionFind tree(N);

    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        tree.unite(x, y);
    }

    int ans = 0;
    rep(i, N) if (tree.same(i, P.at(i)-1)) ans++;

    cout << ans << endl;
}


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

int main()
{
  int n,count;
  count=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n-2;i++)
  {
    if((s.at(i)=='A'&&s.at(i+1)=='B')&&s.at(i+2)=='C')
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, s: "List[int]"):
    tot = sum(s)
    if tot % 10 != 0:
        print(tot)
        return
    m = INF
    for x in s:
        if x % 10 == 0:
            continue
        if x < m:
            m = x
    if m != INF:
        print(tot-m)
    else:
        print(0)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <queue>
#include <cstdio>
#include <cmath>
#include <sstream>
 
using namespace std;
 
typedef long long Long;

struct Trie
{
	struct Node
	{
		int childs[26];
		Node(){
			memset(childs , -1, sizeof(childs));
		}
	};
	vector<Node> V;
	Trie(int reserved = 0)
	{
		V = vector<Node>();
		V.reserve(reserved);
		V.push_back(Node());
	}
	void insert(const string &S)
	{
		int v = 0;
		for(int i = 0; i < S.size(); ++i)
		{
			int p = S[i] - 'a';
			if(V[v].childs[p] == -1){
				V[v].childs[p] = V.size();
				V.push_back(Node());
			}
			v = V[v].childs[p];
		}
	}
	string find(int &k, int v = 0) {
		if (v != 0) {
			k--;
		}
		if (k == 0) return "";
		for (int i = 0; i < 26; ++i) {
			if (V[v].childs[i] != -1) {
				string s = find(k, V[v].childs[i]);
				if (s != "-1") {
					return string(1, i + 'a') + s;
				}
			}
		}
		return "-1";
	}
};

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int k; cin >> k;
	Trie t;
	for (int i = 0; i < s.size(); ++i) {
		int sz = min((int)s.size()-i, 10);
		t.insert(s.substr(i, sz));
	}
	cout << t.find(k) << endl;
}
 
/*
 
gautambishal
5
3 0
2 0 5
3 1
4 0 0
4 3 0

 */
 


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

int main() {
  int n, y;
  cin >> n >> y;
  for (int a = 0; a <= n; a++) {
    for (int b = 0; b + a <= n; b++) {
      int x = y - (10000 * a + 5000 * b);
      if (x < 0) continue;
      if (x % 1000 != 0) continue;
      int c = x / 1000;
      if (a + b + c == n) {
        cout << a << " " << b << " " << c << endl;
        return 0;
      }

    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
} 

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

int n;
double x[100],y[100];

double distance(double p){
  double sum=0;
  for(int i=0;i<n;i++){
    double w=abs(x[i]-y[i]);
    sum += pow(w,p);
  }
  return pow(sum,1.0/p);
}

int main(){
  cout<<fixed<<setprecision(12);

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin>>y[i];
  }
  
  cout<< distance(1) <<endl;
  cout<< distance(2) <<endl;
  cout<< distance(3) <<endl;

  double mx=0;
  for(int i=0;i<n;i++){
    mx=max(mx, abs(x[i]-y[i]) );
  }
  cout<< mx <<endl;
  
  return 0;
}



Measured memory_bytes: 3456
MOD = 10000000007
lim = 200000
MOD = 998244353

inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]


def set_inv(max=lim):
    inv_t[0] = 0
    for i in range(1, max):
        if inv_t[i] == -1:
            _ = mod_inv(i)
            inv_t[i] = _


def mod_inv(x, mod=MOD):
    y, u, v, _x = mod, 1, 0, x
    while y:
        t = _x//y
        _x -= t*y
        _x, y = y, _x
        u -= t*v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u


def mod_pow(a, n, mod=MOD):
    res = 1
    while n:
        if n & 1:
            res = res*a % mod
        a = a*a % mod
        n >>= 1
    return res


def set_factrial(max=lim, mod=MOD):
    c = 1
    factrial[0] = factrial_inv[0] = 1
    for i in range(1, max):
        c *= i
        c %= mod
        factrial[i] = c
        factrial_inv[i] = mod_inv(c, mod)


def comb(a, b, mod=MOD):
    if factrial == -1:
        set_factrial()
    return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % MOD


n, m, k = [int(_) for _ in input().split()]
ans = 0
set_inv()
set_factrial()
for i in range(k+1):
    ans += m*comb(n-1, i)*mod_pow(m-1, n-1 - i)
    ans %= MOD
    # print(ans)
print(ans)


Measured memory_bytes: 32672
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	cn := make([]int, 3)
	for i := 0; i < n; i++ {
		if a[i]%4 == 0 {
			cn[0]++
		} else if a[i]%2 == 0 {
			cn[1]++
		} else {
			cn[2]++
		}
	}

	if cn[0]+1 < cn[2] || cn[0]+1 == cn[2] && cn[1] > 0 {
		fmt.Fprintln(wr, "No")
	} else {
		fmt.Fprintln(wr, "Yes")
	}
}


Measured memory_bytes: 4140