akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n), cnt(n + 1);
    for (int& i : a)
        cin >> i, cnt[i]++;
    int s = 0;
    for (int i = 1; i <= n; i++)
        s += cnt[i] * (cnt[i] - 1) / 2;
    for (int i = 0; i < n; i++)
        cout << s - cnt[a[i]] + 1 << endl;
    GAME_OVER;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#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() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }

  bool ans = true;
  for (auto v : A) {
    if (v % 2 != 0)
      continue;
    if (v % 3 == 0) {
      // ans = false;
      // break;
      continue;
    }
    if (v % 5 == 0) {
      // ans = false;
      // break;
      continue;
    }
    ans = false;
    break;
  }

  if (ans) {
    std::cout << "APPROVED" << std::endl;
  } else {
    std::cout << "DENIED" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
main = do
 a <- (read::String->Double) <$> getLine
 b <- map (read::String->Double).words <$> getLine
 print .floor. minimum $ [f (fromIntegral.ceiling .average b $a) b, 
 						   f (fromIntegral.floor   .average b $a) b]

f ::  Double -> [Double] -> Double
f x y = sum $ map (\h -> (h-x)*(h-x) ) y


average :: [Double] -> Double -> Double
average b a =  sum b / a

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

using namespace std;

int main() {
	int N;
	string S;
	
	cin >> N >> S;
	
	for(int i = 0; i < S.length(); i++) {
		if(S.at(i)+N > 90) {
			S.at(i) = S.at(i) - 26 + N;
		} else {
			S.at(i) += N;
		}
	}
	
	cout << S;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 2e5 + 7;
int dp[N];

void init() {
    dp[0] = 1;
    for (int i = 1; i < N; i++) {
        int some_lose = 0;
        for (int j = 1; j <= 2; j++) {
            if (i - j >= 0 && !dp[i - j]) {
                some_lose = 1;
            }
        }
        if (some_lose) dp[i] = 1;
    }
}

int used[N];
vector<int> g[N];

void dfs(int cur, int ch, pair<int, int> &mx) {
    used[cur] = 1;
    mx = max(mx, {ch, cur});
    for (auto t : g[cur]) {
        if (!used[t]) {
            dfs(t, ch + 1, mx);
        }
    }
}

int solve() {
    pair<int, int> mx = {-1, -1};
    dfs(0, 0, mx);
    int v = mx.second;
    fill(used, used + N, 0);
    mx = {-1, -1};
    dfs(v, 0, mx);
    return mx.first;
}

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

    init();
    // for (int i = 0; i < 10; i++) {
    //     cerr << dp[i] << ' ';
    // }
    // cerr << endl;
    int n;
    cin >> n;
    for (int i = 0; i + 1 < n; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int d = solve();
    if (dp[d]) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
}   


Measured memory_bytes: 22144
from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)
C = Counter(A)
m = 1 << 30
ans = 0

for a in A:
    if C[a] <= 0:
        continue
    C[a] -= 1
    while m > a * 2:
        m >>= 1
    v = m - a
    if v in C and C[v] > 0:
        C[v] -= 1
        ans += 1

print(ans)

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

typedef vector<int> vi;
int main() {
	int N, M;
	cin >> N;
	vi vec1(N);
	rep(i, N)
		cin >> vec1.at(i);
	cin >> M;
	vi vec2(M);
	rep(i, M)
		cin >> vec2.at(i);
	vi vec3;
	set_union(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), inserter(vec3, vec3.end()));
	rep(i, vec3.size())
		cout << vec3.at(i) << endl;
}



Measured memory_bytes: 6448
# include <iostream>


using namespace std;


long long min(long long a, long long b) {
    if (b > a) return a;
    return b;
}


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

    long long ans = a * (n / (a+b));
    long long rem = n % (a+b);
    ans += min(a, rem);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,T,cas=0;
    string s1, s2;
    cin>>s1>>s2;
    cout<<s2<<s1;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int x = in();
  int a = in();
  int b = in();
  int c = (a+x-1)/x*x;
  if(a <= c and c <= b){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
	ll n;
	cin >> n;
	vector<ll> a(n), b(200001, 0);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];

		b[a[i]]++;
	}

	ll ans = 0;
	ll max = *max_element(a.begin(), a.end());
	for (ll i = 0; i < n; i++)
	{
		if (a[i] != max)
		{
			cout << max << endl;
		}
		else
		{
			b[max]--;
			ll t = max;
			for (; b[t] == 0; t--)
			{
			}
			cout << t << endl;
			b[max]++;
		}
	}
}

Measured memory_bytes: 4736
import math

def comb(n, r):
    try: 
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    except:
        return 0

raw = input()
n, m = [int(i) for i in raw.split(" ")]
 
print(comb(n, 2) + comb(m, 2))

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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }

    bool isPal(string s){
        int n=s.size();
        for(int i=0;i<(n/2);i++){
            if(s[i]!=s[n-1-i])
                return false;
        }
        return true;
    }

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        string s;
        cin>>s;
        int n=s.size();
        string a=s;
        string b=s.substr(0,(n-1)/2);
        string c=s.substr((n+3)/2-1, n - (n+3)/2 + 1);
        if(isPal(a) && isPal(b) && isPal(c))
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

bool hv[105];

int main() {
    int n, k; scanf("%d %d", &n, &k);
    for (int i = 0; i < k; i++) {
        int t; scanf("%d", &t);
        for (int j = 0; j < t; j++) {
            int k; scanf("%d", &k);
            hv[k] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!hv[i]) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1708
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
typedef vector<vp> vvp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
  string s;cin>>s;
  for(int i=0;i<s.size();i+=2){
    cout<<s[i];
  }
  cout<<endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i=1;i*i<=n;++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i!=1 && i*i!=n){
                ret.push_back(n/i);
            }
        }
    }
    if(n != 1) ret.push_back(n);
    sort(ret.begin(),ret.end());
    return (ret);
}

int main()
{
    ll a, b; cin >> a >> b;
    ll MIN = min(a,b);
    ll MAX = max(a,b);
    ll ans = 0;
    vector<ll> p(1,1);
    vector<ll> d = enum_div(MIN);
    
        for(ll i=0;i<d.size();i++){
            if(MAX % d[i] == 0){
                int k=0;
                for(ll j=0;j<p.size();j++){
                    if(d[i] % p[j] == 0 && p[j] != 1){
                        k=1;
                        break;
                    }
                }
                if(k==0){
                    p.push_back(d[i]);
                }
            }
        }
    cout << p.size()-1 << endl;
    
    return 0;
}

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

int main() {

    int n;
    cin >> n;
    
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
ll a[100005];
int main() {
	string s;
	ll ans = 0;
	cin >> s;
	ll cnt1 = 0;
	bool fg = true;
	set<char> st;
	rep(i, s.size())
		st.insert(s[i]);
	if (st.size() == 1) {
		cout << 0 << endl;
		return 0;
	}
	char pre = ' ';
	rep(i, s.size()) {
		if (s[i] != pre ) {
			cnt1++;
			pre = s[i];
		}
	}


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

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;
ll a[n+1];
ll b[n+1];
ll sum=0;
rep(i, n){
	cin>>a[i];
	sum+=a[i];
}

ll se=1;
rep(i, n){
if(a[i]>=n){
	se=0;
	break;
}
}

if(se) {cout<<0<<endl;
return 0;}

ll ans=-1;


for(ll s=n-1;s<=(n-1)*n;s++){
	ll possible=1;
	rep(i, n){
		b[i]=a[i];
	}
	ll val=0;
ll cn=sum-s;
if(cn<0){ continue;}
rep(i, n){
	b[i]+=cn;
	b[i]%=n+1;
}

rep(i, n){
	if(b[i]==n) possible=0;
	val+=b[i];
}
if(val==s && possible){
ans=cn;
}
}

cout<<ans<<endl;
return 0;




}




Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

class UnionFind():
    
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n #各要素の親要素の番号を格納するリスト
    
    #要素xが属するグループの根を返す
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    #要素xと要素yが属するグループを併合する   
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        
        if self.parents[x]>self.parents[y]:
            x,y = y,x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    #要素xが属するグループのサイズを返す
    def size(self,x):
        return -self.parents[self.find(x)]
    
    #要素x,yが同じグループかどうかを返す
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    #要素xと同じグループのメンバーを返す
    def members(self,x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    #すべての根の要素を返す
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    
    #グループの数を返す
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return "\n".join("{}: {}".format(r,self.members(r)) for r in self.roots())


if __name__  == "__main__":
    input = sys.stdin.readline
    n,m = map(int,input().split())
    UF = UnionFind(n)
    for i in range(m):
        a,b = map(int,input().split())
        UF.union(a,b)
    q = int(input())
    for i in range(q):
        c,d = map(int,input().split())
        if UF.same(c,d):
            print("yes")
        else:
            print("no")    



Measured memory_bytes: 8328
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n,m;
	cin>>m>>n;
	vector<int>out(m);
	rep(i,m)out[i]=i+1;
	rep(i,n){
		int a,b;
		char d;
		cin>>a>>d>>b;
		swap(out[a-1],out[b-1]);
	}
	rep(i,m)cout<<out[i]<<endl;

}

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

using namespace std;

struct data {
    int tm, s, d;
};

bool cmp(const data &a, const data &b)
{
    return a.tm < b.tm;
}

int main()
{
    int N, M;

    while (cin >> N >> M, N || M) {
        vector<data> log(M);
        vector<bool> ic(N);
        int ans = 1;

        ic[0] = true;
        for (int i = 1; i < N; i++)
            ic[i] = false;

        for (int i = 0; i < M; i++) 
            cin >> log[i].tm >> log[i].s >> log[i].d;
        sort(log.begin(), log.end(), cmp);

        for (int i = 0; i < M; i++) 
            if (ic[log[i].s - 1] && !ic[log[i].d - 1]) {
                ic[log[i].d - 1] = true;
                ans++;
            }
        cout << ans << endl;
    }

    return 0;
}

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

int main() {
  int a, b, c;
  string result;

  cin >> a >> b >> c;

  if (a < b) {
    if (b < c) {
      result = "Yes";
    } else {
      result = "No";
    }
  } else {
    result = "No";
  }

  cout <<  result << endl;

  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    int K,X;cin>>K>>X;
    if(500*K>=X)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 3003;
const int mod = 1e9 + 7;
int a[N];
unsigned long long dp[2][N][N];

void MOD(unsigned long long &x)
{
    if (x >= mod)
        x %= mod;
}

int mpow(int b, int e)
{
    if (e == 0)
        return 1;
    int res = mpow(b, e / 2);
    res = (res * 1LL * res) % mod;
    if (e & 1)
        res = (res * 1LL * b) % mod;
    return res;
}

int main()
{
    int n, q, x, y, i, j;
    bool t = 0;
    long long inv2 = mpow(2, mod - 2);
    cin >> n >> q;
    long long den = mpow(2, q);

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

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            dp[t][i][j] = a[i] > a[j] ? 1 : 0;
        }
    }

    while (q--)
    {
        cin >> x >> y;
        x--, y--;
        MOD(dp[t][x][y] = inv2 * (dp[t][x][y] + dp[t][y][x]));
        dp[t][y][x] = dp[t][x][y];

        for (i = 0; i < n; i++)
        {
            if (i == y or i == x)
                continue;

            MOD(dp[t][x][i] = inv2 * (dp[t][x][i] + dp[t][y][i]));
            dp[t][y][i] = dp[t][x][i];

            MOD(dp[t][i][x] = inv2 * (dp[t][i][y] + dp[t][i][x]));
            dp[t][i][y] = dp[t][i][x];
        }

        t = t;
    }

    unsigned long long ans = 0;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            MOD(ans += dp[t][i][j]);
        }
    }

    MOD(ans = ans * den);

    cout << ans << endl;
    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int x[100010];
int y[100010];
int z[100010];
struct UnionFind
{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int root(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (-d[x] < -d[y])
            swap(x, y); //y.size()が小でx.size()が大にしておきたい
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)]; }
}; 

int main()
{
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);

    rep(i,m)
    {
        cin >> x[i] >> y[i] >> z[i];
        x[i]--;
        y[i]--;
        uf.unite(x[i], y[i]);
    }
    int ans = 0;
    rep(i,n)
    {
        if (uf.d[i] < 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= putStrLn . solve 

solve :: [Int] -> String
solve (_ : a : b : _)
    | odd (b - a - 1) = "Alice"
    | otherwise = "Borys"

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

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

int main(){
  ll A,B,N;
  cin >> A >> B >> N;
  
  ll ng = -1;
  ll ok = N+1;
  ll M = 0;
  while(ok - ng > 1){
    ll mid = (ok+ng)/2;
    ll l = A*mid/B;
    ll r = mid/B;
    ll f = l - A * r;
    if(M <= f){
      ng = mid;
      M = f;
    }
    else{
      ok = mid;
    }
  }
    ll mid = (ok+ng)/2;
  ll l = A*mid/B;
    ll r = mid/B;
    ll f = l - A * r;
  M = max(M, f);
  cout << M << endl;
}

Measured memory_bytes: 3588
def power(m, n, mod = 1_000_000_007)
  n = n.to_s(2).split(//).map(&:to_i)
  result = 1
  n.each{|i|
    result *= result
    if i == 1
      result *= m
    end
    result %= mod
  }
  return result
end
puts power(*(gets.split(" ").map(&:to_i)))

Measured memory_bytes: 8744
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll tree[N << 2], lazy[N << 2];

void propagate(int node, int l, int r){
    if(lazy[node] == 0) return;
    if(l != r){
        lazy[node << 1] += lazy[node];
        lazy[node << 1 | 1] += lazy[node];
    }
    tree[node] += lazy[node];
    lazy[node] = 0;
}

void update(int node, int l, int r, int a, int b, int val){
    if(r < a || l > b) return;
    propagate(node, l, r);
    if(l >= a && r <= b){
        lazy[node] = val;
        propagate(node, l, r);
        return;
    }
    int mid = l + r >> 1;
    update(node << 1, l, mid, a, b, val);
    update(node << 1 | 1, mid + 1, r, a, b, val);
}

ll get(int node, int l, int r, int idx){
    propagate(node, l, r);
    if(l == r){
        return tree[node];
    }
    int mid = l + r >> 1;
    if(idx <= mid) return get(node << 1, l, mid, idx);
    return get(node << 1 | 1, mid + 1, r, idx);
}

pair<int, ll> p[N];
int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, dis, dam;
    cin >> n >> dis >> dam;
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
        a[i] = p[i].first;
    }
    sort(p, p + n);
    sort(a, a + n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll tmp = p[i].second - get(1, 0, n - 1, i);
        if(tmp <= 0) continue;
        ll cost = tmp - tmp % dam;
        if(tmp % dam) cost += dam;
        ans += cost / dam;
        int idx = upper_bound(a, a + n, a[i] + 2 * dis) - a;
        idx--;
        update(1, 0, n - 1, 0, idx, cost);
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 15612
//stringray
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

typedef pair<int,int> pi;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;

#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define pb push_back
#define F first
#define S second
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)


const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

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

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1)ret=(ret*a)%mod;
    (a=a*a)%=mod;
    b>>=1LL;
  }
  return ret;
}

//#define int int64_t
//int a[N+2];

int32_t  main(){
  IOS;
  int n,k;cin>>n>>k;
  if(k==1)cout<<0<<endl;
  else cout<<n-k<<endl;

  return 0;
}



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

int main(){
  int n; cin >> n;
  n %= 1000;
  if (n==0)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << 1000 - n << endl;
  }
  return 0;

}

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

int main() {
    int N;
    cin >> N;
    int result = 0;
    for(int i = 1; i <= N; i = 2 + i) {
        int count = 0;
        for(int j = 1; j <= N; j++) {
            if(i % j == 0) {
                count++;
            }
        }
        if(count == 8) {
            result++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005;
int n,m;
ll ans,sum;
ll p[2*N];
int a[N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		ll l=a[i],r=a[i+1];
		if(l>r)r+=m;
		sum+=r-l;
		if(r-l>1){
            p[l+2]+=1;
            p[r+1]-=r-l;
            p[r+2]+=r-l-1;
		}
	}
	for(int i=1;i<=2*m;i++)p[i]=p[i]+p[i-1];
	for(int i=1;i<=2*m;i++)p[i]=p[i]+p[i-1];
	ll ans=1e18;
	for(int i=1;i<=m;i++)ans=min(sum-p[i]-p[i+m],ans);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		map<long long,long long> m;
		map<long long,long long>::iterator it;
		long long a[n],num[n+1],sum,ans;
//		bool vis[n+1];
//		for(int i=1;i<n+1;i++)
//			num[i]=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
//			num[a[i]]++;
			if(m.find(a[i])==m.end()) m[a[i]]=1;
			else m[a[i]]++;
		}
		sum=0;
		for(it=m.begin();it!=m.end();it++){
			if(it->second>1) sum+=it->second*(it->second-1)/2;
		}
		for(int i=0;i<n;i++){
			ans=sum-(m[a[i]]-1)*m[a[i]]/2+(m[a[i]]-2)*(m[a[i]]-1)/2;
			cout<<ans<<endl;
		}
		
//		if(!m.empty()) m.clear();
		
		
	}
	return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define MN 100005
#define lg long long
struct Node{
	int x,y;
}N[MN];
bool operator<(Node A,Node B){
	return A.y<B.y;
}
int n,tot=0;
int main(){
	scanf("%d",&n);lg res=0;
	for(int i=1,x,y;i<=n;++i){
		scanf("%d%d",&x,&y);res+=x;
		if(x>y)N[++tot].x=x,N[tot].y=y;
	}
	sort(N+1,N+tot+1);
	printf("%lld",tot?res-N[1].y:0);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans=0;
    REP(i,n-1){
        if(s[i]==s[i+1])ans++;
    }
    cout << min(n-1,ans+2*k);
    return 0;
}

Measured memory_bytes: 3720
def solve(string):
    x = int(string)
    a = {i**5: i for i in range(-120, 121)}
    for i in range(-121, 121):
        if x + i ** 5 in a:
            return str(f"{a[x+i**5]} {i}")


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N,a,b,c,d;
  cin>>N;
  a=N/1000;
  b=N/100%10;
  c=N/10%10;
  d=N%10;

  ll res=0;

  ll op1=1;
  ll op2=1;
  ll op3=1;
  string s1="+",s2="+",s3="+";
  FOR(i,0,2){
    FOR(j,0,2){
      FOR(k,0,2){
        if(op1==1){
          op1=-1;
          s1="-";
        }
        else {
          op1=1;
          s1="+";
        }
        res=a+b*op1+c*op2+d*op3;
        //s=""+a+""+s1+""+b+""+s2+""+c+""+s3+""+d;

        //cout<<a<<s1<<b<<s2<<c<<s3<<d<<endl;

      if(res==7)break;
      }

      if(res==7)break;
      if(op2==1){
        op2=-1;
        s2="-";
      }
      else {
        op2=1;
        s2="+";
      }
    }
    if(res==7)break;
    if(op3==1){
      op3=-1;
      s3="-";
    }
    else {
      op3=1;
      s3="+";
    }
  }
  cout<<a<<s1<<b<<s2<<c<<s3<<d<<"=7"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

  string s;
  cin >> s;
  rep(i, s.length()) cout << 'x';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    ll ans = 0;
    for (int a = 1; a < n; ++a) {
        ll b = (n-1)/a;
        ans += b;
    }
    cout << ans << '\n';
    return 0;
}

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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -L_INF;
    chmax(ans, a * c);
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

Measured memory_bytes: 3644
# ABC 089
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
S = [x for x in input().split()]
s = set(S)
if len(s)==3: print('Three')
else: print('Four')

Measured memory_bytes: 3060
N=int(input())
C=list(map(int,input().split()))
Sf=[0]

for i in range(N):
  Sf.append(Sf[i]+C[i])
#print(Sf)

C=C[::-1]
Sb=[0]
for i in range(N):
  Sb.append(Sb[i]+C[i])
Sb=Sb[::-1]
#print(Sb)

ans=10**10
for i in range(1,N):
  ans=min(ans,abs(Sf[i]-Sb[i]))
print(ans)

Measured memory_bytes: 28992
a=65280; b=61680; c=52428; d=43690; e=65535
base = [a, b, c, d, e, 0]
L = {el: 1 for el in base}
for i in range(6):
    R = dict(L)
    for p in R:
        if R[p] < 16:
            L[p ^ e] = min(L.get(p ^ e, 16), R[p] + 1)
        if R[p]+3 < 16:
            for q in R:
                if R[p] + R[q] + 3 <= 16:
                    L[p & q] = min(L.get(p & q, 16), R[p] + R[q] + 3)
                    L[p ^ q] = min(L.get(p ^ q, 16), R[p] + R[q] + 3)
print(*(L[e & eval(s)] for s in open(0).read().replace("-", "~").replace("*", "&").replace("1", "e").split()[:-1]),sep="\n")

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()

typedef long long lint;

struct Edge { int to; lint c; };

struct State {
	int v, h; lint c;
	bool operator > (const State& s) const { return c > s.c; }
};

int N, M, S1, S2, T, BC;
vector< vector< Edge > > adj;
lint dst[2][1010][110], INF = 1LL << 60;

void djk(int index, int s) {
	for_(v,0,N) for_(h,0,BC+1) dst[index][v][h] = INF;
	
	priority_queue< State, vector< State >, greater< State > > que;
	que.push(State{s, 0, 0});
	dst[index][s][0] = 0;
	
	while (!que.empty()) {
		State s = que.top(); que.pop();
		
		if (dst[index][s.v][s.h] < s.c) continue;
		
		for (Edge e : adj[s.v]) {
			lint nxc = s.c + (e.c == -1 ? 0 : e.c);
			int nh = s.h + (e.c == -1 ? 1 : 0);
			
			if (nh <= BC && dst[index][e.to][nh] > nxc) {
				dst[index][e.to][nh] = nxc;
				que.push(State{e.to, nh, nxc});
			}
		}
	}
}

vector< lint > calcX(int index) {
	vector< lint > X;
	
	for_(ki,0,BC+1) for_(kj,ki+1,BC+1) {
		lint di = dst[index][T][ki], dj = dst[index][T][kj];
		lint x = (di - dj) / (kj - ki);
		for_(dx,-1,2) if (di < INF && dj < INF && x + dx >= 0) X.push_back(x + dx);
	}
	
	return X;
}

vector< lint > calcInter() {
	vector< lint > X;
	
	for_(ki,0,BC+1) for_(kj,0,BC+1) {
		if (ki == kj) continue;
		lint di = dst[0][T][ki], dj = dst[1][T][kj];
		lint x = (di - dj) / (kj - ki);
		for_(dx,-1,2) if (di < INF && dj < INF && x + dx >= 0) X.push_back(x + dx);
	}
	
	return X;
}

void solve() {
	djk(0, S1);
	djk(1, S2);
	
	vector< lint > X = calcX(0), XX = calcX(1), XI = calcInter();
	X.insert(X.end(), allof(XX));
	X.insert(X.end(), allof(XI));
	
	sort(allof(X));
	X.erase(unique(allof(X)), X.end());
	
	if (X.empty()) X.push_back(0);
	int m = X.size();
	
	lint ans = INF;
	
	for_(i,0,m) {
		lint x = X[i];
		
		lint dk[2] = {INF, INF};
		for_(j,0,2) for_(k,0,BC+1) dk[j] = min(dk[j], dst[j][T][k] + k * x);
		
		ans = min(ans, abs(dk[0] - dk[1]));
	}
	
	cout << ans << endl;
}

int main() {
	while (cin >> N >> M >> S1 >> S2 >> T, N) {
		--S1; --S2; --T;
		adj.assign(N, vector< Edge >());
		BC = 0;
		
		for_(i,0,M) {
			int u, v;
			string str;
			cin >> u >> v >> str;
			--u; --v;
			
			lint c;
			
			if (str == "x") {
				c = -1;
				++BC;
			} else {
				stringstream ss(str);
				ss >> c;
			}
			
			adj[u].push_back(Edge{v, c});
			adj[v].push_back(Edge{u, c});
		}
		
		solve();
	}
}

Measured memory_bytes: 6828
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a; cin>>a;
    cout<<a + a * a + a * a * a<<endl;
}

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

using namespace std;

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	int ans = 0;
	if (N>K) {
		ans = (N - K)*Y + K * X;
	}
	else {
		ans = N * X;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>

#define	mp	make_pair
#define	x	first
#define	y	second

using namespace std;

typedef	pair<int,int>	pii;

pii forest[100][100];

pii UF_root(pii p){return forest[p.y][p.x].x==-1?p:forest[p.y][p.x]=UF_root(forest[p.y][p.x]);}
void UF_union(pii p,pii q){p=UF_root(p);q=UF_root(q);forest[q.y][q.x]=p;}
bool UF_find(pii p,pii q){return UF_root(p)==UF_root(q);}

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

	char garden[100][101];
	for(int h,w;cin>>h>>w,h;){
		for(int i=0;i<h;i++)	cin>>garden[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)forest[i][j].x=-1;

		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			for(int k=0;k<2;k++){
				int xx=j+dx[k],yy=i+dy[k];
				if(0<=xx && xx<w && 0<=yy && yy<h){
					if(garden[i][j]==garden[yy][xx] && !UF_find(mp(j,i),mp(xx,yy)))
						UF_union(mp(j,i),mp(xx,yy));
				}
			}
		}

		int cnt=0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			if(forest[i][j].x==-1)	cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

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

string title[111],auther[111];
int date[111];
int N,Q;

bool flag[111];
void search1(string s){
  for(int i=0;i<N;i++){
    if( title[i].find(s) == string::npos ) flag[i] = true;
  }
}
void search2(string s){
  for(int i=0;i<N;i++){
    if( auther[i].find(s) == string::npos ) flag[i] = true; 
  }
}
void search3(int day){
  for(int i=0;i<N;i++){
    if( date[i] < day ) flag[i] = true;
  }
}
void search4(int day){
  for(int i=0;i<N;i++){
    if( date[i] > day ) flag[i] = true;
  }
}

int getday(int h,int m,int d){ return h *  1000 + m * 32 + d; }

int main(){
  scanf("%d",&N);
  char buf[111],buf1[111],buf2[111],buf3[111];
  int h,m,d;
  
  for(int i=0;i<N;i++){
    scanf("%s %s %d/%d/%d",buf,buf1,&h,&m,&d);
    title[i] = buf;
    auther[i] = buf1;
    date[i] = getday(h,m,d);
  }
  
  scanf("%d",&Q);
  for(int i=0;i<Q;i++){
    scanf("%s %s %s %s",buf,buf1,buf2,buf3);
    string s;
    memset(flag,0,sizeof(flag));
    if( buf[0] != '*' ){
      s = buf; search1(s);
    }
    if( buf1[0] != '*' ){
      s = buf1; search2(s);
    }
    if( buf2[0] != '*' ){
      sscanf(buf2,"%d/%d/%d",&h,&m,&d);
      search3( getday(h,m,d) );
    }
    if( buf3[0] != '*' ){
      sscanf(buf3,"%d/%d/%d",&h,&m,&d);
      search4( getday(h,m,d) );
    }
    if( i > 0 ) puts("");
    for(int i=0;i<N;i++){
      if( flag[i] == false ){
        printf("%s\n",title[i].c_str());
      }
    }
  }
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef unsigned long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    int x;cin >> x;
    if(x==3||x==5||x==7) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
import sys


def main():
  n, *lst = map(int, sys.stdin.read().split())
  copy = sorted(lst)
  max1, max2 = copy[-1], copy[-2]
  if max2 < max1:
    print(*[max1 if j != max1 else max2 for j in lst], sep='\n')
  else:
    print(*[max1]*n, sep='\n')

    
if __name__ == '__main__':
  main()

Measured memory_bytes: 25036
#include<stdio.h>
int main(){
  char c1,c2,s[110],r[]={"UFRDBL"};
  char d[][10]={"..rr....","..rr....","ggyybbww",
		"ggyybbww","..oo....","..oo...."};
  int i,j,k,X[][14]={
    {2,3,3,2,0,1,2,3,4,5,6,7},
    {2,3,3,2,1,2,3,4,4,3,2,1},
    {4,5,5,4,3,3,3,3,3,3,6,6},
    {2,3,3,2,7,6,5,4,3,2,1,0},
    {6,6,7,7,2,3,5,5,3,2,0,0},
    {0,0,1,1,2,2,7,7,2,2,2,2},
  };
  int Y[][14]={
    {1,1,0,0,2,2,2,2,2,2,2,2},
    {3,3,2,2,3,4,4,3,2,1,1,2},
    {3,3,2,2,0,1,2,3,4,5,3,2},
    {5,5,4,4,3,3,3,3,3,3,3,3},
    {2,3,3,2,0,0,2,3,5,5,3,2},
    {2,3,3,2,1,0,2,3,5,4,3,2}
  };
  scanf("%s",s);
  for(k=0;s[k];k++){
    for(i=0;r[i]-s[k];i++);
    c1=d[Y[i][0]][X[i][0]];
    for(j=1;j<4;j++)d[Y[i][j-1]][X[i][j-1]]=d[Y[i][j]][X[i][j]];
    d[Y[i][3]][X[i][3]]=c1;
    //for(j=0;j<6;j++)printf("%s\n",d[j]);printf("\n");
    c1=d[Y[i][4]][X[i][4]];
    c2=d[Y[i][5]][X[i][5]];//printf("%c %c\n",c1,c2);
    for(j=6;j<12;j++)d[Y[i][j-2]][X[i][j-2]]=d[Y[i][j]][X[i][j]];
    d[Y[i][10]][X[i][10]]=c1;
    d[Y[i][11]][X[i][11]]=c2;
  }
  for(i=0;i<6;i++)printf("%s\n",d[i]);
  return 0;
}
    

Measured memory_bytes: 524