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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

using namespace std;

int main() {
  in(int, n, m);
  vector<P> v;
  rep(i, m) {
    in(int, a, b);
    v.push_back({a, b});
  }
  sort(all(v));
  int ans = 0;
  priority_queue<int> que;
  for (auto [a, b] : v) {
    if (!que.empty() && -que.top() <= a) {
      ++ans;
      while (!que.empty()) que.pop();
    }
    que.push(-b);
  }
  out(ans + 1);
}


Measured memory_bytes: 4436
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, sum int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	if sum%10 > 0 {
		fmt.Println(sum)
		return
	}
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < N; i++ {
		w := sum - a[i]
		if w%10 > 0 {
			fmt.Println(w)
			return
		}
	}
	fmt.Println(0)
}

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

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

using namespace std;
typedef long long ll; 

int main(void){
	
	int N, Q;
	cin >> N >> Q;
  
	vector<pair<int,int>> ab(N-1);
	vector<int> ans(N);
	rep(i, N-1)
		cin >> ab[i].first >> ab[i].second;
 
	sort(ab.begin(), ab.end());
  
	rep(i, Q){
		int p, x;
		cin >> p >> x;
		ans[p-1] += x;
	}
  
	rep(i, N-1)
		ans[ab[i].second-1] += ans[ab[i].first-1];
  
	rep(i, N)
		cout << ans[i] << " ";
	
	return 0;
}


Measured memory_bytes: 4736
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    import bisect

    N, W = read_values()
    I = [tuple(read_values()) for _ in range(N)]

    init_w = I[0][0]
    D = {i: [] for i in range(4)}
    S = {i: [0] for i in range(4)}
    for w, v in I:
        bisect.insort(D[w - init_w], -v)

    for i, d in D.items():
        for v in d:
            S[i].append(v + S[i][-1])

    res = 0
    for t0 in range(len(D[0]) + 1):
        for t1 in range(len(D[1]) + 1):
            for t2 in range(len(D[2]) + 1):
                for t3 in range(len(D[3]) + 1):
                    if (t0 + t1 + t2 + t3) * init_w + t1 + 2 * t2 + 3 * t3 > W:
                        continue

                    res = min(res, S[0][t0] + S[1][t1] + S[2][t2] + S[3][t3])
    print(-res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 40432
n = int(input())
A = list(map(int, input().split()))

d = dict()

for a in A:
    d[a] = d.get(a, 0) + 1

x = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 2]
y = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 4]

if x == [] and y == []:
    print(0)
else:
    ans = 0
    if len(x) >= 2:
        ans = max(ans, x[0][0] * x[1][0])
    if len(y) >= 1:
        ans = max(ans, y[0][0]**2)
    print(ans)

Measured memory_bytes: 27040
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
#define X 1000000007
using namespace std;
bool debug=false;

int main(){
  int n,a[105];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long ans=INF;

  for(int i=-100;i<=100;i++){
    long long x=0;
    for(int j=0;j<n;j++){
      x+=pow((a[j]-i),2);
    }
    if(debug)cout<<i<<":"<<x<<endl;
    ans=min(ans,x);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define MAX 2000000
int A[MAX],B[MAX],C[MAX];
int k=10000;int n;
void countingsort(int A[],int B[]){
    rep(i,0,k+1)C[i]=0;
    rep(j,1,n+1)C[A[j]]++;
    rep(i,1,k+1)C[i]=C[i]+C[i-1];
    for(int i=1;i<=n;i++){
        B[C[A[i]]]=A[i];
        C[A[i]]--;
    }
}
int main(){
    cin>>n;
    rep(i,1,n+1)cin>>A[i];
    countingsort(A,B);
    rep(i,1,n){
        cout<<B[i]<<" ";
    }
    cout<<B[n]<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

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

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> a;
int main(void){
  int n;
  int mx, mc;
  int s = 0;
  mx = 0;
  cin >> n;
  a.resize(n);
  rep(i,n){
    cin >> a[i];
    if (a[i] > mx){
      s = mx;
      mx = a[i];
      mc = 1;
    }else if(a[i] == mx){
      mc++;
    }else if(a[i] > s){
      s = a[i];
    }
  }
  rep(i, n){
    if(a[i] == mx && mc == 1){
        cout << s << endl;
    }else{
      cout << mx << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2432
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll a, b, c;
  cin >> a >> b >> c;

  if(a%2 == 0 || b%2 == 0 || c%2 == 0) cout << 0 << endl;
  
  else if(a%2 == 1 && b%2 == 0 && c%2 == 0) cout << b*c << endl;
  else if(a%2 == 0 && b%2 == 1 && c%2 == 0) cout << a*c << endl;
  else if(a%2 == 0 && b%2 == 0 && c%2 == 1) cout << b*a << endl;
  else if(a%2 == 1 && b%2 == 1 && c%2 == 0) {
    if(a > b) cout << b*c << endl;
    else cout << a*c << endl;
  }
  else if(a%2 == 1 && b%2 == 0 && c%2 == 1) {
    if(a > c) cout << b*c << endl;
    else cout << a*b << endl;
  }
  else if(a%2 == 0 && b%2 == 1 && c%2 == 1) {
    if(b > c) cout << c*a << endl;
    else cout << b*a << endl;
  }
  else if(a%2 == 1 && b%2 == 1 && c%2 == 1) {
    if(a >= b && a >= c) cout << b*c << endl;
    else if(b >= a && b >= c) cout << a*c << endl;
    else cout << a*b << endl;
  }
  
  return 0;
}


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

int main() {
  vector<int> x(3);
  for (int i=0; i<3; i++) {
      cin >> x.at(i);
  }
  sort(x.begin(),x.end());
  for (int i=0; i<3; i++) {
      cout << x.at(i);
      if(i<2) cout << " ";
      else cout << endl;
  }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
  

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vvl G(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  priority_queue<ll>c;
  rep(i,n){
    ll x;
    cin >> x;
    c.push(x);
  }
  vector<ll>ans(n,-1);
  queue<int>q;
  q.push(0);
  ans[0]=c.top();
  c.pop();
  while(!q.empty()){
    int v=q.front();
    q.pop();
    for(int nv:G[v]){
      if(ans[nv]!=-1)continue;
      ans[nv]=c.top();
      c.pop();
      q.push(nv);
    }
  }
  ll sum=0;
  rep(i,n)sum+=ans[i];
  cout << sum-*max_element(all(ans)) << endl;
  rep(i,n){
    if(i!=0)cout << " ";
    cout << ans[i];
  }
  
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, sum=0;
    cin >> n;

    vector<int> a(n-1);
    rep(i, n-1) cin >> a[i];
    
    vector<int> b(n);
    b[0] = a[0];
    b[n-1] = a[n-2];

    for(int i=1; i<n-1; i++){
        b[i] = min(a[i-1], a[i]);
    }
    rep(i, n) sum += b[i];

    out(sum);
    
}

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

void solveA(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;

  cout << H*W- (h*W+w*H) + h*w << endl;
}
void solveB(){
  int n,m,c;
  cin >> n >> m >> c;
  int ans=0;

  int b[m];

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

  for(int i =0 ;i<n ; i++){
    int sum=0;
    for(int j =0 ;j<m ; j++){
      int a;
      cin >> a;
      sum += a * b[j];		   
    }
    if (sum+c > 0) ans++;
  }

  cout << ans << endl;
}
void solveC(){
  long long n,m;
  cin >> n >> m;
  map<long,long> mp;
  long long k = 0;
  long long ans = 0;

  long long a,b;
  for(long long i = 0; i<n ; i++){
    cin >> a >> b;
    if (mp.count(a) == 0){
      mp[a] = b;
    }
    else{
      mp[a] += b;
    }
  }
  for (auto x: mp)
    {
      if (x.second >= m){
	ans += m*x.first;
	break;
      }
      else{
	ans += x.second*x.first;
	m -= x.second;
      }
      
    }
  cout << ans << endl;
  
}

void solveD(){
  long long a,b;
  cin >> a >> b;
  long long top = 0;
  long long count = (b-a+1);
  if(a%2==1){
    top=a;
    count--;
  }

  long long ans;
  if(count/2%2==0) ans = 0;
  else ans = 1;

  if(count%2==1) ans = ans ^ b;

  cout << (ans^top) << endl;
}

int main(){
  solveD();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){

    int N;
    cin >> N;

    vector<int> pos1(N);
    vector<int> pos2(N);
    rep(i, N){
        int p;
        cin >> p;
        p--;
        pos1[p] = i;
        pos2[p] = N - i - 1;
    }

    ll ans = 0;
    multiset<int> st1;
    multiset<int> st2;

    auto add1 = [&](int i){
        st1.insert(i);
    };
    auto add2 = [&](int i){
        st2.insert(i);
    };

    for(int i = N - 1; i >= 0; i--){
        auto it1 = st1.upper_bound(pos1[i]);
        auto it2 = st2.upper_bound(pos2[i]);
        if(it1 == st1.end() and it2 == st2.end()){
            add1(pos1[i]);
            add2(pos2[i]);
            continue;
        } else if(it1 == st1.end()){
            int l = *it2;
            auto it3 = st2.upper_bound(l);
            int r = (it3 == st2.end() ? N : *it3);
            ans += (ll)(i + 1) * (ll)(r - l) * (ll)(pos2[i] + 1);
        } else if(it2 == st2.end()){
            int l = *it1;
            auto it3 = st1.upper_bound(l);
            int r = (it3 == st1.end() ? N : *it3);
            ans += (ll)(i + 1) * (ll)(r - l) * (ll)(pos1[i] + 1);
        } else {
            int l1 = *it1;
            int l2 = *it2;
            auto it3 = st1.upper_bound(l1);
            auto it4 = st2.upper_bound(l2);
            l2 = N - 1 - l2;
            int r1 = (it3 == st1.end() ? N : *it3);
            int r2 = (it4 == st2.end() ? -1 : N - 1 - *it4);
            ans += (ll)(i + 1) * (ll)(l2 - r2) * (l1 - pos1[i]);
            ans += (ll)(i + 1) * (ll)(r1 - l1) * (pos1[i] - l2);
        }
        add1(pos1[i]);
        add2(pos2[i]);
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 10368
ts = []
(0..2**6).each do |x|
  t = 'KIHBR'
  (0..5).each do |i|
    if (x & (1<<i)) > 0 && [0, 3, 4, 5].include?(5-i)
      t[5-i, 0] = 'A'
    end
  end
  ts << t
end
ts.uniq!
puts ts.include?(gets.chomp) ? 'YES' : 'NO'


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

void solve() {
    int N, K, S;
    cin >> N >> K >> S;
    int n = S;
    int m = S + 1;
    if(n == 1e9) m = S - 1;
    rep(i, K) cout << n << " ";
    for(int i = K; i < N; ++i) cout << m << " ";
    cout << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3604
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

_, D1 = MAP()
_, D2 = MAP()

if D1+1 == D2:
	print("0")
else:
	print("1")


Measured memory_bytes: 5268
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int x, a, b;
    cin >> x >> a >> b;

    print((x - a) % b);
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using Int = int64_t;
int main() {
    Int N;
    cin >> N;
    vector<Int> A(N), S(N + 1, 0);
    for (Int i = 0; i < A.size(); i++) {
        cin >> A[i];
        S[i + 1] = S[i] + A[i];
    }
    sort(S.begin(), S.end());
    Int ans = 0, t = 1;
    for (Int i = 1; i < S.size(); i++) {
        if (S[i] == S[i - 1]) t++;
        else {
            ans += t * (t - 1) / 2;
            t = 1;
        }
        if (i == S.size() - 1 && t > 1) ans += t * (t - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
template<typename T>
inline void read(T& s)
{
    s=0;int f=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){s=s*10+c-'0';c=getchar();}
    s*=f;
}
char str[200005];
int n;
int main()
{
	scanf("%s",str);
	n=strlen(str);
	int gg=0;
	long long ans=0;
	for(int i=0;i<n;i++)
		if(str[i]=='W')
		{
			ans+=(i-gg);
			gg++;
		}
	cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char* argv[]){
    char str[1024];
    int tmp;
    scanf("%s", str);
    if(str[(tmp=strlen(str))-1]=='s'){
        str[tmp] = 'e';
        str[tmp+1] = 's';
        str[tmp+2] = '\0';
    }else {
        str[tmp] = 's';
        str[tmp+1] = '\0';
    }
    printf("%s\n", str);
    return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#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 Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> a(4);
    rep(i,4) cin >> a[i];
    sort(all(a));
    int x = a[0] + a[3];
    int y = a[1] + a[2];
    cout << abs(x-y) << endl;

}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 


int main() {
    int s,w;
    cin >> s >> w;
    cout << ((s <= w) ? "unsafe" : "safe") << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int main (){
	vector <long> imos;
	std::map<long , long > maps;
	std::map<long, bool> boolmaps;
	imos.push_back(0);
	maps[0]++;
	boolmaps[0] = true;
	long a,MOD;
	cin >> a >> MOD;
	long temp;
	rep(i,a){
		cin >> temp;
		imos.push_back((imos[i]+temp)%MOD);
		maps[imos[i+1]]++;
		boolmaps[imos[i+1]] = true;
	}
	long ans = 0;
	rep(i,a+1){
		if(boolmaps[imos[i]]==true){
			boolmaps[imos[i]]=false;
			ans = ans + (maps[imos[i]]-1)*maps[imos[i]]/2;
		}
	}
	cout << ans << endl ;
	return 0;
}


Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 ll a,b;
  cin>>a>>b;
  if(a==1&&b==2){
cout<<3<<endl;
  }
  else if(a==2&&b==1){
cout<<3<<endl;
  }
  else if(a==1&&b==3){
cout<<2<<endl;
  }
  else if(a==3&&b==1){
cout<<2<<endl;
  }
  else{
     cout<<1<<endl;
  }
}

Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int a = scan.nextInt();
        if (h % a == 0) {
            System.out.println(h / a);
        } else {
            System.out.println(h / a + 1);
        }
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int N; cin >> N;
  vector<pair<int, int>> A(N);
  int tmp, i;
  rep(i,N){
      cin >> tmp;
      A[i] = make_pair(tmp,i+1);
  }
  sort(A.begin(), A.end());
  rep(i,N){
      cout << A[i].second;
      if(i<N-1){cout << " ";}else{cout << endl;}
  }

  return 0;
}


Measured memory_bytes: 4040
n = int(input())
s = input()

t = [0] * n
for i in range(n):
    if s[i] == 'E':
        t[i] = 1
    if i == 0:
        continue
    t[i] += t[i-1]

ans = 10000000000

for i in range(n):
    if i == 0:
        a = 0
    else:
        a = i - t[i-1]
    b = t[n-1] - t[i]
    c = a + b

    ans = min(ans, c)

print(ans)


Measured memory_bytes: 15264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZE 10000000
vector<int> prime;
vector<int> factors;
ll sieve[SIZE+5];

void primeSieve(int n)
{
    sieve[0] = sieve[1] = 1;
    prime.push_back(2);
    for(int i = 4; i <= n; i += 2)
    {
        sieve[i] = 1;
    }
    for(int i = 3; i*i <= n; i += 2)
    {
        if(sieve[i] == 0)
        {
            for(int j = i*i; j <= n; j += 2*i)
            {
                sieve[j] = 1;
            }
        }
    }
    for(int i = 3; i <= n; i += 2)
    {
        if(sieve[i] == 0)
        {
            prime.push_back(i);
        }
    }

}

ll NOD ( int n ) {
    int sqrtn = sqrt ( n );
    ll res = 1;
    for ( int i = 0; i < prime.size() && prime[i] <= sqrtn; i++ ) {
        if(sieve[n] == 0)
            break;
        if ( n % prime[i] == 0 ) {
            int p = 0;
            while ( n % prime[i] == 0 ) {
                n /= prime[i];
                p++;
            }
            sqrtn = sqrt ( n );
            p++;
            res *= p;
        }
    }
    if ( n != 1 ) {
        res *= 2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    primeSieve(SIZE);
    ll sum = 0;
    for(int i = 1; i <= n; i++)
    {
        sum += (i*NOD(i))%10000000000000;
    }
    cout << sum << endl;
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

double R;

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

    const double PI = std::acos(-1);

    std::cin >> R;

    double res = R * 2 * PI;
    printf("%.10f\n", res);
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
template<class T = int> using V = vector<T>;

using R = long double;
constexpr R pi = acos((R)-1), eps = 1e-10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; cin >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, P p) { return o << fixed << setprecision(15) << real(p) << ' ' << imag(p); }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  P abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};
int ccw(L s, P p) { return ccw(s.s, s.t, p); }

P intxn(L l, L m) {
  assert(sgn(crs(l.vec(), m.vec())));
  return l.s + crs(m.s - l.s, m.vec()) / crs(l.vec(), m.vec()) * l.vec();
}

int main() {
  V<P> a(3), b(3);
  int loop = 0;
  while (cin >> a[0] >> a[1] >> a[2]) {
    cin >> b[0] >> b[1] >> b[2];
    int res = 5;
    auto dfs = [&](const auto& dfs, int n, int k) -> void {
      {
        auto _a = a, _b = b;
        sort(begin(_a), end(_a), cmp);
        sort(begin(_b), end(_b), cmp);
        if (eql(_a[0], _b[0]) and eql(_a[1], _b[1]) and eql(_a[2], _b[2])) {
          res = min(res, n);
          return;
        }
      }
      if (n + 1 >= res) return;
      for (int i = 0; i < 3; ++i) {
        if (eql(a[i], b[0])) continue;
        if (eql(a[i], b[1])) continue;
        if (eql(a[i], b[2])) continue;
        L l{a[i], a[i] + a[(i + 2) % 3] - a[(i + 1) % 3]};
        for (P p : b) if (~ccw(l, p) & 1) {
          P t = a[i];
          a[i] = p;
          dfs(dfs, n + 1, k);
          a[i] = t;
        }
        if (!k) for (int s = 0; s < 2; ++s) {
          int i1 = (i + 1 + s) % 3;
          int i2 = (i + 2 - s) % 3;
          for (P p : b) {
            if (eql(p, a[0])) continue;
            if (eql(p, a[1])) continue;
            if (eql(p, a[2])) continue;
            L m{a[i2], a[i2] + a[i1] - p};
            if (!sgn(crs(l.vec(), m.vec()))) continue;
            P q = intxn(l, m);
            P t = a[i];
            a[i] = q;
            dfs(dfs, n + 1, k + 1);
            a[i] = t;
          }
        }
      }
    };
    dfs(dfs, 0, 0);
    if (res == 5) cout << "Many\n";
    else cout << res << '\n';
    // cerr << ++loop << '\n';
  }
}


Measured memory_bytes: 3216
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int m = cin.NextInt();
			Console.WriteLine(48 - m);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

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

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

int main(){
  int l, r, d; cin >> l >> r >> d;
  int count = 0;
  for(int i=l; i<=r; i++){
    if(i%d==0) count++;
  }
  cout << count << "\n";
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> buttons(n);

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    // 1 index to 0 index
    buttons.at(i) = a - 1;
  }

  bool ok = false;
  int cnt = 0;
  int pos = 0;
  while (true) {
    int nextPos = buttons.at(pos);
    cnt++;
    if (nextPos == 1) {
      ok = true;
      break;
    }
    if (nextPos == pos) {
      break;
    }
    if (cnt > n) {
      break;
    }
      
    pos = nextPos;
  }
      
  if (ok) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}

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

int ans=0;
int H,W;

void bfs(vector<string> &S,int sy,int sx,int ey,int ex){
	vector<int> vx={0,1,0,-1};
  vector<int> vy={1,0,-1,0};
  queue<int> quex;
  queue<int> quey;
  quex.push(sx);
  quey.push(sy);
  vector<vector<int>> dis(H,vector<int>(W,1e9));
  dis.at(sy).at(sx)=0;
  while(!quex.empty() && !quey.empty()){
    int x=quex.front();
    int y=quey.front();
    quex.pop();
    quey.pop();
    for(int i=0;i<4;i++){
      int next_x=x+vx.at(i);
      int next_y=y+vy.at(i);
			if(next_x<0 || next_x>=W || next_y<0 || next_y>=H)	continue;
      if(S.at(next_y).at(next_x)=='#')  continue;
      if(dis.at(next_y).at(next_x)!=1e9)  continue;
      quex.push(next_x);
      quey.push(next_y);
      dis.at(next_y).at(next_x)=dis.at(y).at(x)+1;
    }
  }
	if(dis.at(ey).at(ex)!=1e9)	ans=max(ans,dis.at(ey).at(ex));
}

int main(){
	cin >> H >> W;
	vector<string> S(H);
	for(int i=0;i<H;i++)	cin >> S.at(i);

	for(int st_i=0;st_i<H;st_i++){
		for(int st_j=0;st_j<W;st_j++){
			for(int en_i=0;en_i<H;en_i++){
				for(int en_j=st_j;en_j<W;en_j++){
					if(S.at(st_i).at(st_j)=='#')	continue;
					if(S.at(en_i).at(en_j)=='#')	continue;
					bfs(S,st_i,st_j,en_i,en_j);
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())


def souwa(n):
    syo, jyoyo = divmod(n, 2)
    return (n + 1) * syo + (n + 1) // 2 * jyoyo


print(souwa(n) - souwa(n//3)*3 - souwa(n//5)*5 + souwa(n//15)*15)

Measured memory_bytes: 9168
import itertools
N, M, Q = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(Q)]
# print(nums)
# 長さN
# 数字はMまで
num_permutations = list(
    map(list, itertools.combinations_with_replacement(list(range(1, M + 1)), N)))
# print(num_permutations)

maxcount = 0
for num_permutation in num_permutations:
    count = 0
    # print(num_permutation)
    for num in nums:
        # print(num)
        if num_permutation[num[1] - 1] - num_permutation[num[0] - 1] == num[2]:
            count += num[3]
            # print(num[3])
    maxcount = max(maxcount, count)
    # print(count)
    # print('=======================')
print(maxcount)


Measured memory_bytes: 84468
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>

using namespace std;
int po(int n)
{
    int i;
    for(i=0; n%2==0; i++)
    {
        n/=2;
    }
    return i;
}
int main()
{
    int n,i,a;
    scanf("%d",&n);
    int p[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&p[i]);
    }
    for(i=0,a=0; i<n; i++)
    {
        a+=po(p[i]);
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,kk=INT_MAX,v,mn,sum=0;
     for(int i=0;i<5;i++)
     {
         cin>>v;
         mn=v%10;
         if(mn<kk && mn!=0)
            kk=mn;
         if(v%10!=0)
         v=((v/10)+1)*10;
         sum+=v;
     }
     if(kk==INT_MAX)
        cout<<sum<<endl;
     else
     cout<<sum-(10-kk)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

ll dam[100100],mountain[100100];

int main(void) {
  int N; cin >> N;
  reps(i,N) cin >> dam[i];
  ll sum = 0, even_sum = 0;
  reps(i,N) sum += dam[i];
  for(int i = 2; i <= N; i+=2){
    even_sum += dam[i];
  }
  mountain[1] = sum - 2 * even_sum;
  cout << mountain[1];
  reps(i,N){
    if (i==1) continue;
    mountain[i] = 2 * dam[i-1] - mountain[i-1];
    cout << " " << mountain[i];
  }
  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 2816
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <tuple>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<vector<PII> > VVPII;
typedef priority_queue<PII, vector<PII>, greater<PII> > PQPII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};

//other
//--------------------------------------------
#define RANGE(a, c, b) ((a <= b) && (b < c))

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int INF = (int) 10e9;

int solve(int n, int m){
	VVPII node(n);
	vector<bool> done(n, false);
	char comma;
	REP(i, m){
		int from, to, cost;
		cin >> from >> comma >> to >> comma >> cost;
		node[from].PB(MP(cost, to));
		node[to].PB(MP(cost, from));
	}
	PQPII q;
	int result = 0;
	q.emplace(0, 0);
	VI costs(n, INF);
	while(!q.empty()){
		int w = q.top().first, u = q.top().second;
		q.pop();
		if(costs[u] < w) continue;
		result += w > 0 ? (w / 100) - 1 : 0 ;
		for(PII p : node[u]){
			if(p.first < costs[p.second] && !done[p.second]){
				done[u] = true;
				costs[p.second] = p.first;
				q.emplace(p.first, p.second);
			}
		}
	}
	return result;
}

int main(int argc, char const *argv[])
{
	for(int n, m; cin >> n, n;){
		cin >> m;
		cout << solve(n, m) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1e9
//S.size()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;

int main(void){
  int D,N; cin>>D>>N;
  if(D == 0){
    if(N == 100)cout<<101;
    else cout<<N;
  }
  else if(D == 1 && N == 100)cout<<10100;
  else if(D == 2 && N == 100)cout<<1010000;
  else{
    int num = 1;
    for(int i = 0;i < D;i++){
      num *= 100;
    }
    cout<<num * N;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define MOD 1000000007
 
using namespace std;
 
int main() {
  int n;
  scanf("%d", &n);
    // printf("%d\n", n);
  vector<int> nums(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &nums[i]);
    sum += nums[i];
    sum %= MOD;
  }
  long long result = 0;
  for (int i = 0; i < n; ++i) {
    sum -= nums[i];
    // printf("%d\n", nums[i]);
    sum += MOD;
    sum %= MOD;
    result += (long long)sum * (long long)nums[i];
    result %= MOD;
  }

  printf("%lld", result);
  
  return 0;
}

Measured memory_bytes: 4040
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <bitset>
#include <functional>

using namespace std;

#define FOR(i,n) 		for(int(i)=0;(i)<(int)(n);(i)++)
#define FORN(i,a,b,c) 	for(int(i)=a;i<(int)(b);i+=(c))
#define RES(x,nilai)	memset(x,nilai,sizeof(x));
#define pb              push_back
#define mp              make_pair
#define INF				1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline string IS(int a){
    char x[100];
    sprintf(x,"%d",a); string s = x;
    return s;
}

inline int SI(string a){
    char x[100]; int res;
    strcpy(x,a.c_str()); sscanf(x,"%d",&res);
    return res;
}

//==============================================

bool cmp(int x,int y) {return x>y;}

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("13.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	for(int i =1; i <=9;i++) {
        for(int j =1; j<=9;j++) {
cout << i << 'x' << j << '=' << i*j << endl;
}
        }
		
    return 0;
}

Measured memory_bytes: 3072
S = input()

chars = set()
all_chars = set([c for c in 'abcdefghijklmnopqrstuvwxyz'])

for c in S:
    chars.add(c)

diff = list(all_chars - chars)
diff = sorted(diff)

if len(diff) == 0:
    print(None)
else:
    print(diff[0])
    

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

int a,b,c;
multiset<string> S;
string s1,s2,t;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
	for (int i=1;i<=a;i++) S.insert("a");
	for (int i=1;i<=b;i++) S.insert("b");
	for (int i=1;i<=c;i++) S.insert("c");
	for (int i=1;i<a+b+c;i++) {
		t=*S.begin()+*(--S.end());
		S.erase(S.begin()); S.erase(--S.end());
		S.insert(t);
	}
	cout << *S.begin();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int 
#define MOD 1000000007 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
int gcd(int a,int b){if(a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (max(a,b)/gcd(a,b))*min(a,b);}
int powermodm(int x,int n,int M){int result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}



main()
{
    fastIO;
    int t;
    t=1;
    while(t--)
    {
        int n;
        cin >> n;
        int h[n];
        for(int i=0;i<n;i++) cin >> h[i];
        int dp[n];
        dp[0]=0;
        dp[1]=abs(h[0]-h[1]);
        for(int i=2;i<n;i++)
        {
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
        cout << dp[n-1];
    }
    
    
    
    
    
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  char** arr=new char*[H];
  for(int i=0;i<H;i++){
    arr[i]=new char[W];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>arr[i][j];
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(arr[i][j]=='.'){
        int num=0;
        if(i>0&&j>0){
          if(arr[i-1][j-1]=='#') num++;
        }
        if(i>0){
          if(arr[i-1][j]=='#') num++;
        }
        if(i>0&&j+1<W){
          if(arr[i-1][j+1]=='#') num++;
        }
        if(j>0){
          if(arr[i][j-1]=='#') num++;
        }
        if(j+1<W){
          if(arr[i][j+1]=='#') num++;
        }
        if(i+1<H&&j>0){
          if(arr[i+1][j-1]=='#') num++;
        }
        if(i+1<H){
          if(arr[i+1][j]=='#') num++;
        }
        if(i+1<H&&j+1<W){
          if(arr[i+1][j+1]=='#') num++;
        }
        arr[i][j]='0'+num;
      }
  	cout<<arr[i][j];
    }
   cout<<endl; 
  }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    
    sort(p.begin(), p.end());
       
    int ans = 0;
    for (int i = 0; i < k; i++)
        ans += p[i];
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3620
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::min;

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();
    let n: u32 = s.len() as u32;

    let mut cnt: u32 = 0;
    for c in cv {
        if c == '0' {
            cnt += 1;
        }
    }

    println!("{}", 2 * min(cnt, n - cnt));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
	int m,n;
	cin>>m>>n;
	int sum=0;
	while(n--){
		int x;
		cin>>x;
		sum+=x;
	}
	m-=sum;
	if(m<0){
		cout<<-1;
	}
	else{
		cout<<m;
	}

	return 0;
}

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

int main(){
  string N;
  
  cin >> N;
  
  int sum = 0;
  
  for(int i = 0; i< N.size(); i++){
    sum += (int)(N[i] - '0');
  }
  
  if(sum % 9 == 0){
    cout << "Yes"<< endl;
  }
  
  else{
    cout << "No" << endl;
  }
}
    
  

Measured memory_bytes: 3732
import itertools

num = int(input())
c = [i + 1 for i in range(num)]

a = tuple([int(i) for i in input().split(" ")])
b = tuple([int(i) for i in input().split(" ")])

a_num = 0
b_num = 0

for num,i in enumerate(itertools.permutations(c)):
    if a == i:
        a_num = num
    if b == i:
        b_num = num

print(abs(a_num - b_num))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    int a[300000] = {};
    a[0] = a[1] = 0;
    for (int i = 2; i <= 2 * 123456; i++) {
        bool devide = false;
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) devide = true;
        }
        if (!devide) a[i] = 1;
    }
    for (int i = 0; i < 2 * 123456; i++) a[i + 1] += a[i];
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        cout << a[2 * n] - a[n] << endl;
    }
    return 0;
} 


Measured memory_bytes: 4208
import sys
input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

from math import gcd
    
INF = float('inf')
NIL = - 1

n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(gcd(i, j), k)
print(ans)




Measured memory_bytes: 9580