akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    vector<ll> a(n),f(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>f[i];
    sort(a.rbegin(),a.rend());
    sort(f.begin(),f.end());
    ll mt = 0;
    ll Mt = 1e12;
    ll kk = k;
    while(mt<Mt){
        ll t = (mt+Mt)/2;
        kk=k;
        for(int i=0; i<n; i++){
            ll b = t/f[i];
            kk -= max(0LL,a[i]-b);
        }
        if(kk<0){
            mt = t+1;
        }else{
            Mt = t;
        }
    }
    cout<<Mt<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  string S = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  S.erase(remove(S.begin(), S.end(),' '), S.end());
  string buf;
  int K;
  cin >> K;
  vector<string> v;
  stringstream ss{S};
  while(getline(ss, buf, ',')) {
    v.push_back(buf);
  }
  cout << v[K-1] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int dp[2000][2000];



int main(){
	int W;
	int n;
	int c=0;
	while(cin>>W){
		c++;
		if(W==0)break;
		char ch;
		int w[2000],v[2000];
		rep(i,2000)rep(j,2000)dp[i][j]=-999999999;
		cin>>n;
		rep(i,n){
			cin>>v[i]>>ch>>w[i];
		}

		int maxval=-1;
		int maxwait=-1;

		dp[0][0]=0;
		for(int i=1;i<=n;i++){
			rep(j,W+1){
				dp[i][j] = max(dp[i][j],dp[i-1][j]);
				if(j-w[i-1]>=0)
					dp[i][j] = max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1] );

				if(maxval<dp[i][j]){
					maxval=dp[i][j];
					maxwait=j;
				}
				if(maxval==dp[i][j] && maxwait>j){
					maxval=dp[i][j];
					maxwait=j;
				}
//				cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
			}
		}
		cout<<"Case "<<c<<":"<<endl;
		cout<<maxval<<endl;
		cout<<maxwait<<endl;
	}
}

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


int main() {
  int N;
  cin >> N;
  vector<int> ve(N);
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> ve.at(i);
  }
  
  for (int i = 0; i<N; i++){
  	  for (int j = i+1; j < N; j++){
      	sum = sum + ve.at(i)*ve.at(j);
      }
  }
  
  cout << sum << endl;
  
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int n, k;
int p[1005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p, p + n);
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3660
# エラトステネスの篩, 累積和
def make_prime_table(N):
    sieve = list(range(N + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(N ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, N + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


max_lr = 10 ** 5

prime_table = make_prime_table(max_lr)

cs = [0] * (max_lr + 1)
for i in range(3, max_lr + 1, 2):
    j = (i + 1) // 2
    if prime_table[i] == i and prime_table[j] == j:
        cs[i] = 1
for i in range(1, max_lr + 1):
    cs[i] += cs[i - 1]

Q = int(input())
result = []
for _ in range(Q):
    l, r = map(int, input().split())
    result.append(cs[r] - cs[l - 1])
print('\n'.join(str(i) for i in result))


Measured memory_bytes: 24696
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
N,X=map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
n=len(x)-1
d=[0]*n
for i in range(n):
  d[i]=x[i+1]-x[i]
print(gcd_list(d))

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

int main() {
    int N,K;
    bool D[10] = {false};
    cin >> N >> K;
    for(int i=0; i<K; ++i) {
        int d; cin >> d;
        D[d] = true; 
    }
    while(1) {
        int tmp = N;
        bool flag = false;
        while(tmp) {
            if(D[tmp % 10]) {
                flag = true;
                break;
            }
            tmp /= 10;
        }
        if(flag) {
            ++N; continue;
        } else {
            cout << N << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
  
int main(void){
int a,b,c,tmp;
scanf("%d %d %d\n",&a,&b,&c);
if(a>b) {
tmp=a;
a=b;
b=tmp;
}
if(b>c) {
tmp=b;
b=c;
c=tmp;
}
if(a>b) {
tmp=a;
a=b;
b=tmp;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int calc(int A) {
  if (A <= 0) return 0;
  A++;
  int ans = 0;
  for (int i = 0; i < 50; i++) {
    int loop = (1LL << (i + 1));
    int cnt = (A / loop) * (loop / 2);
    cnt += max(0LL, (A % loop) - (loop / 2));
    if (cnt % 2 == 1) 
    ans += 1LL << i;
  }

  return ans;
}

signed main() {
  int A, B;
  cin >> A >> B;
  int ans = calc(B) ^ calc(A - 1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll ans=1;
  sort(a,a+n);
  //cout<<INT_MAX<<endl;
  ll maxi = pow(10,18);
 // cout<<maxi<<endl;
  for(ll i=0;i<n;i++)
  {
    if(a[i]==0)
    {
      ans =0;
      break;
    }
    if(ans<=maxi/a[i])
      ans*=a[i];
    else
    {
      ans=-1;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4420
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
	}
	else if (b<0) {
		if ((b - a) % 2 == 0) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}
	else {
		cout << "Positive" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int K;
    string S;
    cin >> K >> S;
    string ans;
    if(S.size()>K){
        ans = S.substr(0,K);
        ans += "...";
    }else{
        ans = S;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
;;; Utils

(defmacro read-numbers-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))


(defmacro read-line-to-array (dimension)
  (if (< dimension 0)
      (error "invalid arguments for dimension.")
      `(make-array ,dimension :initial-contents (read-numbers-to-list))))

(defmacro read-line-to--char-list ()
  `(concatenate 'list (read-line)))

(defmethod make-cumlative-sum ((sequence list))
  (labels ((inner (sequence &optional (acc '(0)))
             (if (null sequence)
                 (reverse acc)
                 (inner (rest sequence) (cons (+ (first sequence)
                                                 (first acc))
                                              acc)))))
    (inner sequence)))





(defmethod princ-for-each-line ((sequence list))
  (labels ((inner (sequence)
             (if (null sequence)
                 nil
                 (progn
                   (fresh-line)
                   (princ (first sequence))
                   (inner (rest sequence))))))
    (inner sequence)))

(defmethod princ-for-each-line ((sequence array))
  (dotimes (i (length sequence))
    (fresh-line)
    (princ (aref sequence i))))



;;; Write code here

(defparameter *mod* (+ (expt 10 9) 7))

(defun solve (n xs &optional (ans 0))
  (let ((xs-cum (rest (make-cumlative-sum xs))))
    (loop repeat (1- n)
       do (progn (setf ans (mod (+ ans
                                   (* (first xs-cum)
                                      (second xs)))
                                *mod*))
                 (pop xs-cum)
                 (pop xs)))
    ans))


(defun main ()
  (let ((n (read))
        (xs (read-numbers-to-list)))
    (format t "~a~%" (solve n xs))))

(main)


Measured memory_bytes: 84116
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	string s; cin >> s;
	int count = 0;
	rep(i,s.size()){
		if (s[i]=='x'){
			count++;
		}
	}
	if (15-count >= 8){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  int n;
  cin>>n;
  ve hed;
  ll ko=0;
  for (int i = 0; i < n; ++i)
  {
    ll yo;
    cin>>yo;
    hed.pb(yo);
    if(i!=0)ko^=yo;
  }
  ve ans;
  ll num=ko;
  ans.pb(num);
  for (int i = 1; i < n; ++i)
  {
    ll cur1=hed[0]^hed[i];
    ll vol=0;
    for (int i = 0; i <= 64; ++i)
    {
      if(cur1&(1<<i)){
        if(!(num&(1<<i))){
          vol|=(1<<i);
        }
      }
      else{
        if((num&(1<<i))){
          vol|=(1<<i);
        }
      }
    }
    ans.pb(vol);
  }
  for(auto it:ans)cout<<it<<" ";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a;
	cin>>a;
	if(a==1)
	{
		printf("Hello World");
		return 0;
	}
	else
	{
		int b,c;
		cin>>b>>c;
		cout<<b+c<<endl;
	}
	return 0;
}

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



int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    int cnt = 0;
    rep(i,n) {
        if((i+1)%2 == 1 && a[i]%2 == 1)
            cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}




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

int main(){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
 
  vector<int> fig = {a, b, c, d, e};
  
  bool flag = false;
  
  for (int i = 0; i < 4; i++) {
    for (int j = i; j <= 4; j++) {
      if (fig.at(j) - fig.at(i) > k) {
        flag = true;
        break;
      }
    }
  }
  
  if (flag) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

int n,k,i,s=0;
cin>>n>>k;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];

}

sort(a,a+n);
for(i=0;i<k;i++)
{
s=s+a[i];

}

cout<<s<<endl;

return 0;
}

Measured memory_bytes: 3636
a, b, c = map(int,input().split())
k = int(input())

for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    if a < b and b < c:
        print("Yes")
        exit()
        #print(a,b,c)

print("No")

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

dp=[[[0]*(sum(X)+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0]=1

for i in range(1,n+1): #x_1,x_2...x_n
  for k in range(i):   #k枚数選ぶ
    for j in range(sum(X)+1): #合計
      if dp[i-1][k][j]:
        dp[i][k+1][j+X[i-1]]+=dp[i-1][k][j]
        dp[i][k][j]+=dp[i-1][k][j]
ans=0
for i in range(1,n+1):
  for j in range(1,sum(X)+1):
    if j==i*a:
      ans+=dp[n][i][j]
print(ans)

Measured memory_bytes: 54004
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, k ] <- readInts
	uncurry ( printf "%d %d\n" ) $ takahashi a b k

takahashi a b 0 = ( a, b )
takahashi a b k = aoki d ( b + d ) $ k - 1
	where
		d = a `div` 2
	

aoki a b 0 = ( a, b )
aoki a b k = takahashi ( a + d ) d $ k - 1
	where
		d = b `div` 2

Measured memory_bytes: 508
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ll n;
    cin >> n;
    ll p[10];
    p[0] = 1;
    for(ll i=1;i<10;i++)    p[i] = (p[i-1] * 10);
    string s = to_string(n);
    ll m = s.size();
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        string temp = to_string(i);
        ll l = temp[0]-'0';
        ll f = temp[temp.size()-1]-'0';
        if(f==0)  { continue;  }
        if(f==l && f<=n)   ans++;
        ll temp1 = f*10+l;
        if(temp1<=n)    ans++;
        ll ten = 10;
        for(ll j=3;j<m;j++)
        {
            ans += ten;
            ten *= 10;
        }
        if(m>2)
        {
            if(s[0]>temp[temp.size()-1])     ans += ten;
            else if(s[0]<temp[temp.size()-1]){}
            else
            {
                for(ll i=1;i<=m-2;i++)
                {
                    ll extra = s[i] - '0';
                    ans = (ans + extra*p[m-2-i]);
                }
                if(s[s.size()-1]>=temp[0])   ans++;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	deque<char> deq;
	string s;
	cin >> s;
	rep(i, s.size()){
		if(s[i] == 'B'){
			if(!deq.empty()) deq.pop_back();
		}else{
			deq.push_back(s[i]);
		}
	}
	while(!deq.empty()){
		cout << deq.front();
		deq.pop_front();
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<pair<int, int>> xy(n);
  int mn = INF, mx = 0;
  map<int, int> blue;
  REP(i, n) {
    int x, y; cin >> x >> y;
    if (x > y) swap(x, y);
    xy[i] = {x, y};
    chmin(mn, x);
    chmax(mx, y);
    ++blue[y];
  }
  sort(ALL(xy));
  ll ans = 1LL * (xy[n - 1].first - xy[0].first) * (blue.rbegin()->first - blue.begin()->first);
  vector<pair<int, int>> idx(n);
  REP(i, n) idx[i] = {-xy[i].second, i};
  sort(ALL(idx));
  REP(i, n) {
    int x, y; tie(x, y) = xy[idx[i].second];
    --blue[y];
    if (blue[y] == 0) blue.erase(y);
    ++blue[x];
    chmin(ans, 1LL * (mx - mn) * (blue.rbegin()->first - blue.begin()->first));
  }
  cout << ans << '\n';
  return 0;
}


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

int main( ){
  while(1){
    int n,s,sum=0;
    string a;
    cin>>a>>n;
    if(a=="-")break;
    for(int i=0;i<n;i++){
      cin>>s;
      sum+=s;
    }
    sum%=a.size();
    a=a+a.substr(0,sum);
    a=a.erase(0,sum);
    cout<<a<<endl;
  }
  return 0;
}


Measured memory_bytes: 3164
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int F(long long A, long long B) {
    int cntA, cntB;
    cntA = cntB = 0;
    while (A != 0) {
        cntA++;
        A /= 10;
    }
    while (B != 0) {
        cntB++;
        B /= 10;
    }
    return max(cntA, cntB);
}

int main() {

    long long N;
    cin >> N;

    int ans = 10;
    for (long long i = 1; i*i <= N; i++) {
        if (N%i == 0)ans = min(ans, F(i, N / i));
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N,Y;
  int x,y,z;
  bool check = false;
  cin >> N >> Y;
  for(int i=N;i>=0;--i){
    for(int j=N-i;j>=0;--j){
      if(10000*i+5000*j+1000*(N-i-j) == Y){
          x = i;
          y = j;
          z = N-i-j;
          check = true;
          break;
      }
    }
  }
  if(check){
    cout << x << ' ' << y << ' ' << z << endl;
  }else{
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long M = long.Parse(str[1]);
		long ans = 0;
		long ct = 0;
		string[] str2 = Console.ReadLine().Split();
		var table = new Dictionary<long, long>();
		table[0] = 1;
		for(var i=0;i<N;i++){
			ct = (ct + long.Parse(str2[i])) % M;
			bool contains = table.ContainsKey(ct);
			if(contains){
				ans += table[ct];
				table[ct] += 1;
			} else {
				table[ct] = 1;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 20320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <cstring>
#include <queue>
#include <stdlib.h>

using namespace std;

#define mod (1000000007)
typedef long long  ll;
typedef vector<int> vi;


ll exp(ll a, ll n) {
  if (n==0) return 1;
  if (n == 1) return a;
  if (n%2) {
    ll s = exp(a,n-1);
    return s * a;
  } else {
    ll s = exp(a,n/2);
    return s*s;
  }
}

long max(long a, long b) {
  if (a < b) return b;
  return a;
}

int min(int a, int b, int c) {
  return min(min(a,b), min(b,c));
}


void solve() {
  int n, k;
  cin >> n >> k;
  vi arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  
  vi dp(n, INT_MAX);
  
  dp[0] = 0;
  if (n > 1) dp[1] = abs(-arr[1]+arr[0]);
  
  
  for (int i = 1; i < n; i++) {
    for (int j = i-1; j >= max(0, i-k); j--) {
      dp[i] = min(dp[i], dp[j] + abs(arr[j]-arr[i]));
    }
  }

  cout <<  dp[n-1] << "\n";
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 4032
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Integer[] scanResult = scan();
		Arrays.sort(scanResult, Comparator.reverseOrder());

		System.out.println(calc(scanResult));
	}

	private static Integer[] scan() {

		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		Integer[] arr = new Integer[size];
		for (int i = 0; i < size; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	private static int calc(Integer[] arr) {

		int aliceTotal = 0;
		int bobTotal = 0;

		for (int i = 0; i < arr.length; i++) {

			if (i % 2 == 0) {
				aliceTotal += arr[i];
			} else {
				bobTotal += arr[i];
			}
		}
		return aliceTotal - bobTotal;
	}
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.ARC071
{
    class LTLT
    {
        static long Mod = 1000000007;
        public static void Main()
        {
            var nm = ReadLine();
            var x = ReadLine().Trim().Split(' ').Select(i => long.Parse(i)).ToArray();
            var y = ReadLine().Trim().Split(' ').Select(i => long.Parse(i)).ToArray();
            long xArea = 0;
            for (var left = 1; left < x.Length; ++left)
                xArea = (xArea + (x[left] - x[left - 1]) * left * (x.Length - left)) % Mod;
            long yArea = 0;
            for (var left = 1; left < y.Length; ++left)
                yArea = (yArea + (y[left] - y[left - 1]) * left * (y.Length - left)) % Mod;
            WriteLine(xArea * yArea % Mod);
        }

    }
}


Measured memory_bytes: 39204
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  while(true){
    c -= b;
    if(c<=0) break;
    a -= d;
    if(a<=0) break;
  }
  if(c<=0) cout <<"Yes\n";
  else cout <<"No\n";
}


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

int d, s, t;

void solve() {
    cin >> d >> s >> t;
    cout << (s*t >= d ? "Yes\n" : "No\n");
}

int main() {
    // int t; cin >> t;
    // while(t--)
        solve();
}

Measured memory_bytes: 3564
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    b = True
    for i in range(len(s)):
        if t[i] != s[-i-1]:
            b = False
            break
    print("YES" if b else "NO")


if __name__ == '__main__':
    slove()


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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i=0; i<N; i++) cin >> a.at(i);

	int cnt =0;
	for(int i=0; i<N; i=i+2){
		if(a.at(i)%2 != 0) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int A, B, T;
  std::cin >> A >> B >> T;

  // Main
  int res = ((T) / A) * B;

  // Output
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%2==0) continue;
        int s=0;
        for(int j=1;j<=i;j++)
            if(i%j==0) s++;
        if(s==8) ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    trace(A,n);
  }

  return 0;
}


/*AOJ answer
#include<stdio.h>
 
static const int N = 1000;
 
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}
 
int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);
 
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
   
  trace(A, n);
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    trace(A,n);
  }
 
  return 0;
}
*/



Measured memory_bytes: 2084
N,K = list(map(int,input().split()))
TDlist = []

for x in range(0,N):
    TDlist.append(list(map(int,input().split())))

TDlist= sorted(TDlist, key = lambda x: x[1],reverse=True)
kinds = set()
seconds = []
answer = 0

for x in TDlist[:K]:
    if not x[0] in kinds:
        kinds.add(x[0])
    else:
        seconds.append(x[1])
    answer += x[1]

answer += len(kinds)**2
score = answer

for x in TDlist[K:]:
    if seconds == []:
        break
    if x[0] in kinds:
        continue
    kinds.add(x[0])
    y = seconds.pop()
    score += (x[1] - y) + (len(kinds)*2 -1)
    answer = max(score,answer)

print(answer)

Measured memory_bytes: 30848
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
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;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve(long long N, std::string S){
    ll cnt=0;
    for (ll i = 0; i < N-2; i++) {
        if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
            cnt++;
            i++;
            i++;
        }
    }
    cout << cnt << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
def resolve():
    S = input()
    cnts = [0] * 2019
    cnts[0] = 1
    num, d = 0, 1

    for s in S[::-1]:
        num += int(s) * d
        d *= 10
        num %= 2019
        d %= 2019
        cnts[num] += 1

    ans = 0
    for cnt in cnts:
        ans += cnt * (cnt - 1) // 2
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,d;
    cin >> n >> d;
    int X[n][d];
    REP(i,n) REP(j,d) cin >> X[i][j];

    int cnt = 0;
    REP(i,n){
        FOR(j,i+1,n){
            int ssum = 0;
            REP(k,d) ssum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);

            int tmp = 0;
            while(1){
                tmp ++;
                if( tmp * tmp == ssum){
                    cnt ++;
                    break;
                }
                if(tmp * tmp > ssum) break;

            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for( ll i=0 ; i<n ; i++ )
#define f(i, a, b) for( ll i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}

ll index(ll n)
{
    n = double(n);
    double sol = n*n + n;
    sol = sol*2 + 1;
    double ans = -1 + sqrt(sol);
    ans = ans/2;
    ans = ll(ans);
    return ans;
}
vector<ll> SieveOfEratosthenes(ll n,ll a)
{

    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    vector<ll>v;
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (ll p= a; p<=n; p++)
       if (prime[p])
          v.push_back(p);
    return v;
}
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i =0;
    ll ans =0;
    while(i<n)
    {
        if(s[i]=='A' && s[i + 1]=='B' && s[i + 2] == 'C' && i + 2<n)
        {
            ans++;
            i += 3;
        }
        else
        {
            i++;
        }
    }
    cout<<ans;

}


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



int main() {
string a;
cin>>a;

for(int i=0;i<a.size();i++){
for(int j=0;j<a.size();j++){
	if(i==j)continue;
if(a[i]==a[j]){
cout<<"no"<<endl;
return 0;
}
}
}
cout<<"yes"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  ll total = 0;
  vector<ll> h(n);
  rep(i,n) cin >> h[i]; 
  sort(h.begin(),h.end(), greater<int>());
  rep(i,n) {
    if(i < k){
      continue;
    } else {
      total += h[i];
    }
  } 
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 1792
def combi(n,k)
  k=n-k if 2*k > n
  return 1 if k == 0
  return ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end
n=gets.chomp.to_i
sum=0
hash=Hash.new(-1)
hash[0]=1
a=gets.chomp.split(" ").map(&:to_i)
a.each{|i|
  sum+=i
  if hash[sum].to_i==-1 then
    hash[sum]=0
  end
  hash[sum]=hash[sum].to_i+1
}
ans=0
hash.values.each{|v|
  ans+=combi(v,2) unless v<2
}
puts(ans)


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

using namespace std;



int main(){

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

sort(A,A+N);



if (H<=accumulate(A,A+N,0))
{
  cout << "Yes";
}
else  cout << "No";

return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i++)
int main(void){
  int maze[20][20];
  int maze1[20][20];
  int prv[20][20];
  int n,m;
  int a,b,c,d;
  cin>>n>>m;
  rep(i,n)rep(j,n)maze[i][j]=maze1[i][j]=10000000;
  while(m--){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    maze[--a][--b]=c;
    maze[b][a]=d;
  }
  
  
  rep(k,n)rep(i,n)rep(j,n){
    maze[i][j]=min(maze[i][j],maze[i][k]+maze[k][j]);
  }
  
  scanf("%d,%d,%d,%d",&a,&b,&c,&d);
  
  cout<<-maze[--a][--b]-maze[b][a]+c-d<<endl;
}

Measured memory_bytes: 1240
fun main(array: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map{ it.toInt() }
    val s = readLine()!!

    repeat(a) {
        if(s[it] !in '0'..'9') {
            print("No")
            return
        }
    }
    if(s[a] != '-') {
        print("No")
        return
    }
    for(i in a+1 until a+b) {
        if(s[i] !in '0'..'9') {
            print("No")
            return
        }
    }
    print("Yes")
}

Measured memory_bytes: 37932
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	l, r, d := nextInt(), nextInt(), nextInt()
	ans := r/d - (l-1)/d
	puts(ans)
}


Measured memory_bytes: 1780
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.length();
  long long ans=0;
  int mod=2019;
  long long suff=0;
  long long pot=1;
  vector<long long>cntsuff(mod,0);
  for(int i=n-1;i>=0;i--){
    int digit=s[i]-'0';
    suff=(suff+digit*pot)%mod;
    if(suff==0)
      ans++;
    pot=(pot*10)%mod;
    ans+=cntsuff[suff];
    cntsuff[suff]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3720
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut x: Vec<isize> = (0..m)
        .map(|_| iterator.next().unwrap().parse().unwrap())
        .collect();
    x.sort();

    let mut diffs: Vec<usize> = Vec::with_capacity(m);
    for i in 0..(m - 1) {
        diffs.push((x[i + 1] - x[i]) as usize);
    }

    diffs.sort();
    for _ in 0..min(n - 1, m - 1) {
        diffs.pop();
    }

    let ans: usize = diffs.iter().sum();

    return ans.to_string();
}


Measured memory_bytes: 8444
#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
  int x;
  cin >> x;
  for(int i = 0; ; ++i) {
    int base = i * 100;
    if(base > x) {
      cout << 0 << endl;
      break;
    }
    int mini = 0;
    int maxi = 5 * i;
    if(mini <= x-base && x-base <= maxi) {
      cout << 1 << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3176
n,w  = map(int, (input().split()))
goods = [list(map(int, input().split())) for _ in range(n)]

dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, w+1):
        #print(dp)
        if j - goods[i-1][0] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-goods[i-1][0]] + goods[i-1][1])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[n][w])


Measured memory_bytes: 171784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int H,W,K;
vector<string> fi;

int solve(){
    int res=INF;
    rep(bit,1<<(H-1)){
        bool gok=true;
        int N=0;
        vector<int> ord(H,0);
        rep(i,H-1){
            if(!(bit & 1<<i)) ord[i+1]=ord[i];
            else ord[i+1]=ord[i]+1,N++;
        }

        int add=0;
        vector<int> nums(N+1,0);
        rep(w,W){
            vector<int> one(N+1,0);
            bool ok=true;
            rep(h,H){
                one[ord[h]]+=fi[h][w]-'0';
                nums[ord[h]]+=fi[h][w]-'0';
                if(one[ord[h]]>K) gok=false;
                if(nums[ord[h]]>K) ok=false;
            }
            if(!ok) add++,nums=one;
        }
        if(gok) res=min(res,N+add);
    }

    return res;
}

int main(){
    cin>>H>>W>>K;
    fi.resize(H);
    rep(i,H) cin>>fi[i];
    cout<<solve()<<endl;
}

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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    int N;cin>>N;
    int T[N];
    REP(i,N){
        cin>>T[i];
    }
    int M;cin>>M;
    int P;int X;
    int ans[M];
    REP(i,M){
        ans[i]=0;
        cin>>P;
        cin>>X;
        REP(j,N){
            if(j==P-1){
                ans[i]+=X;
            }else{
                ans[i]+=T[j];
            }
        }
    }
    REP(i,M){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,L;
	cin >> N >> L;
	vector<long long> A(N);
	for(int i =0; i < N; i++) cin >> A[i];
	for(int i =1; i < N; i++) if(A[i-1]+A[i] >= L) {
		cout << "Possible\n";
		for(int j =0; j < i-1; j++) cout << j+1 << "\n";
		for(int j =N-2; j > i-1; j--) cout << j+1 << "\n";
		cout << i << "\n";
		return 0;}
	cout << "Impossible\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 1664