akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) a<b ? a:b
// #define max(a, b) a < b ? b : a
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define endl "\n"
#define pb push_back
#define pi 3.14159265358979323846

// int explore(vector<vector<int>> &adj,int x,int y,vector<int> &visited)
// {
//     if(x==y)
//     return 1;
//     visited[x]=1;
//     for(int i=0;i<adj[x].size();i++)
//     {
//         if(!visited[adj[x][i]])
//         {
//             if(explore(adj,adj[x][i],y,visited))
//             return 1;
//         }
//     }
//     return 0;
// }
bool valley(int p[], int k)
{
    if (p[k] < p[k - 1] && p[k] < p[k + 1])
        return true;
    return false;
}
bool peak(int p[], int k)
{
    if (p[k] > p[k - 1] && p[k] > p[k + 1])
        return true;
    return false;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
int const N=10000007;
int prime[N];
// for(int i=1;i<=n;i++)
//         {
//             if(a[i]==maxi)
//             {
//                 ctr++;
//                 ans=max(ans,ctr);
//             }
//             else
//             ctr=0;
//         }
int32_t main() 
{
    // IOS;
    // int t;
    // cin>>t;
    // while(t--)
    // {
            string s;
            cin>>s;
            int ctr=0;
            for(int i=0;i<s.size();i++)
            {
                ctr+=(s[i]-'0');
            }
            if(ctr%9==0)
            cout<<"Yes";
            else
            cout<<"No";

    // }

}

Measured memory_bytes: 3720
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll A, B; cin >> A >> B;
  ll ans = (B + A - 1) / A * A;
  ll s1 = ans / B + (ans % B / A) + (ans % B % A);
  ll s2 = ans / A;
  if (s2 < s1) cout << ans << endl;
  else cout << -1 << endl;
}



Measured memory_bytes: 3228
package main
import "fmt"
import "sort"
func main(){
    // Your code here!
    var n int
    fmt.Scan(&n)
    t := make([]string, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t[i])
    }

    l := len(t)
    max_len := 0
    m := make(map[string]int)
    
    for i := 0; i < l; i++ {
        if _, ok := m[t[i]]; ok {
            m[t[i]] =  m[t[i]] + 1
        }else{
            m[t[i]] = 1
        }
    }
    for _, value := range m {
        if max_len < value{
            max_len = value
        }
    }
    var ss []string
    for key, value := range m {
        if value == max_len{
            ss = append(ss, key)
        }
    }
    
    sort.Strings(ss)
    for i := 0; i < len(ss); i++{
        fmt.Println(ss[i])
    }
}

Measured memory_bytes: 40704
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    string S;
    cin >> S;

    ll Q;
    cin >> Q;

    ll T, F, count = 0;
    char tmp;
    string L, R, M;

    rep(i, Q) {
        cin >> T;
        if (T == 1) {
            count++;
        }
        else {
            cin >> F >> tmp;
            if (count % 2 == 0) {
                if (F == 1) {
                    L = tmp + L;
                }
                else {
                    R = R + tmp;
                }
            }
            else {
                if (F == 1) {
                    R = R + tmp;
                }
                else {
                    L = tmp + L;
                }
            }
        }
    }

    S = L + S + R;

    if (count % 2 != 0) {
        reverse(S.begin(), S.end());
    }

    cout << S;

    return 0;
}

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

namespace Competitive
{

    internal class Solution
    {
        public long[] P; // 1, 2, 4, 8
        public long N;
        public long[] DP;

        public void Run()
        {
            var P = Input.ReadLongArray();
            N = Input.ReadLong() * 4;

            DP = new long[8 + 1];
            DP[0] = 0;
            for (int i = 1; i < DP.Length; i++)
            {
                DP[i] = long.MaxValue;
                if (i - 1 >= 0) DP[i] = Math.Min(DP[i], DP[i - 1] + P[0]);
                if (i - 2 >= 0) DP[i] = Math.Min(DP[i], DP[i - 2] + P[1]);
                if (i - 4 >= 0) DP[i] = Math.Min(DP[i], DP[i - 4] + P[2]);
                if (i - 8 >= 0) DP[i] = Math.Min(DP[i], DP[i - 8] + P[3]);
            }

            long unit = N / 8;
            long mod = N % 8;

            Console.WriteLine(unit * DP[8] + DP[mod]);
        }

    }

    // libs ----------
    
    // common ----------

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n][m];
  int b[m];
  for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for(int i = 0; i < m; i++) scanf("%d", &b[i]);
  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++){
      sum += a[i][j] * b[j];
    }
    printf("%d\n", sum);
  }
}



Measured memory_bytes: 2788
import sys
s=0
p=[list(map(float,e.split(',')))for e in sys.stdin]
x,y=p[0]
print(abs(sum((p[i][0]-x)*(p[i+1][1]-y)-(p[i][1]-y)*(p[i+1][0]-x)for i in range(1,len(p)-1)))/2)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c;
	cin>>k;
	for(int i=0;i<k;i++){
		if(a>=b){
			if(a<=c){
				c=2*c;
			}
			else{
				a=2*a;
			}
		}
		else{
			if(b<=c){
				c=2*c;
			}
			else{
				b=2*b;
			}
		}
	}
	cout<<a+b+c;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define int long long
using namespace std;

signed main() {
	int a; string b;
	cin >> a >> b;
	int J[100000], I[100000], j = 0, i = 0;
	for (int c = 0; c < a; c++) {
		if (b[c] == 'J')j++;
		J[c] = j;
	}
	for (int d = a - 1; d != -1; d--) {
		if (b[d] == 'I')i++;
		I[d] = i;
	}
	int sum, MAX, l, r; sum = MAX = l = r = 0;
	for (int e = 0; e < a; e++) {
		MAX = max(MAX, J[e] * I[e]);
		if (b[e] == 'O') {
			sum += J[e] * I[e];
			l += J[e];
			r += I[e];
		}
	}
	cout << sum + max(MAX, max(l, r)) << endl;
}

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

int x[10][10];
map<string,int> m;

int last(string s){
    int now=0;
    for (int i=0;i<4;++i)
        now=x[now][s[i]-'0'];
    return now;
}

int check(string s){
    int now=0;
    for (int i=0;i<5;++i)
        now=x[now][s[i]-'0'];
    return now;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    for (int i=0;i<10;++i)
        for (int j=0;j<10;++j)
            cin >> x[i][j];
    string pre="",now,alt;
    for (int i=99999;i>=0;--i){
        if (i==9999) pre+='0';
        if (i==999) pre+='0';
        if (i==99) pre+='0';
        if (i==9) pre+='0';
        now=pre+to_string(i);
        m[now]=check(now);
    }
    int ans=0,ok;
    pre="";
    for (int i=9999;i>=0;--i){
        if (i==999) pre+='0';
        if (i==99) pre+='0';
        if (i==9) pre+='0';
        now=pre+to_string(i);
        now+='0'+last(now);
        ok=0;
        for (int i=0;i<5;++i){
            for (int j=0;j<10;++j){
                alt=now;
                alt[i]='0'+j;
                if (now!=alt&&m[alt]==0) ok=1;
            }
        }
        for (int i=0;i<4;++i){
            if (now[i]==now[i+1]) continue;
            swap(now[i],now[i+1]);
            if (m[now]==0) ok=1;
            swap(now[i],now[i+1]);
        }
        ans+=ok;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 14260
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int main()
{
 	ios::sync_with_stdio(false);
	ll s;cin>>s;
	int h = 1e9;
	int y = (s+h-1)/h;
	int k = s-1LL*(y-1)*h;
	cout << y-1 << " " << 0 <<" ";
	cout << 0 << " "<< k << " ";
	cout << y << " " << h << endl;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())

xyz=[]
for x in range(N+1):   
    for y in range(N-x+1):
        z=N-(x+y)
        total=10000*x+5000*y+1000*z
        if total==Y:
            xyz.append([x,y,z])
if xyz:
    print(xyz[0][0],xyz[0][1],xyz[0][2])
else:
    print(-1,-1,-1)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main() {FIN;
	ll a,b,c;
	cin>>a>>b>>c;
	c=min(c,a+b+1);
	cout<<b+c<<"\n";	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#define int long long int

using namespace std;

main()
{
    //freopen("input.txt", "r", stdin);
    int N;
    cin>>N;
    vector<int> A(N);
    vector<pair<int, int> > cnt(N);
    map<int, int> Min;
    map<int, int> Cnt;
    int s = 0;
    for(int i = 0; i < N; ++i)
    {
        cin>>A[i];
        s += A[i];
    }
    map<int, int> level;
    int cur = 0;
    vector<int> B(N);
    for(int i = 0; i < N; ++ i)
    {
        B[i] = A[i];
    }
    sort(B.begin(), B.end());
    int c = N;
    int prev = 0;
    for(auto el:B)
    {
        cur += (el - prev) * c;
        c--;
        level[el] = cur;
        prev = el;
    }
    for(int i = 0; i < N; ++i)
    {
        cnt[i].first = level[A[i]];
        //cout<<i<<' '<<level[A[i]]<<endl;
        cnt[i].second = i;
    }
    sort(cnt.begin(), cnt.end());
    vector<int> ans(N+1);
    int have = 0;
    int now = N
    ;
    for(int i = N - 1; i >= 0; -- i)
    {
        //cout<<cnt[i].first<<' '<<cnt[i].second<<' '<<now<<endl;
        if (cnt[i].second < now)
        {
            ans[now] = -cnt[i].first + have;
            have = cnt[i].first;
            now = cnt[i].second;
        }
    }
    //cout<<now<<endl;
    if (now < N)
    {
        ans[now] = level[A[now]];
    }
    ans.pop_back();
    for(auto el:ans)
    {
        cout<<el<<endl;
    }


}



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

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

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

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

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

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

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

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

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

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

signed main() {
	int n;
	cin >> n;
	rep (i, n) {
		int x; cin >> x;
		if (x % 2 == 0) {
			if (!((x % 3 == 0) or (x % 5 == 0))) {
				puts("DENIED");
				return 0;
			} 
		}
	}

	puts("APPROVED");

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (300001)
#define MOD (1000000007)

// 指定された要素以上の値が現れる最初の位置のイテレータ
typedef int lb;
int lower_bound(lb* a, lb val, int len)
{
    int l = 0;
    int r = len;
    while(l!=r)
    {
        int m = (l+r)/2;
        if(a[m]<val) l = m+1;
        else r = m;
    }
    return l;
}

int c[MAXN];
int cs[MAXN];
int main(void)
{
    ll n;
    scanf("%ld",&n);
    for(int i=0;i<n;i++)
    {
        ll a;
        scanf("%ld",&a);
        c[a]++;
    }
    qsort(c,MAXN,sizeof(int),acs);
    cs[0] = c[0];
    for(int i=1;i<MAXN;i++) cs[i]=cs[i-1]+c[i];
    
    for(int k=1;k<=n;k++)
    {
        int ans = n/k;
        for(;ans>0;ans--)
        {
            int i = lower_bound(c,ans,MAXN);
            int s = i>0 ? cs[i-1] : 0;
            s += (MAXN-i)*ans;
            if(s>=(ans*k)) break;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

vector<int> makeTable(const vector<ll>& s) {
    int n = s.size();
    vector<int> ret(n + 1);
    ret[0] = -1;
    int j = -1;
    for (int i = 0; i < n; i++) {
        while (j >= 0 && s[i] != s[j]) j = ret[j];
        ret[i + 1] = ++j;
    }
    return ret;
}

vector<int> kmp(const vector<ll>& str, const vector<ll>& word) {
    vector<int> table = makeTable(word), ret;
    int m = 0, i = 0, n = str.size();
    while (m + i < n) {
        if (word[i] == str[m + i]) {
            if (++i == (int)(word.size())) {
                ret.push_back(m);
                m = m + i - table[i];
                i = table[i];
            }
        }
        else {
            m = m + i - table[i];
            if (i > 0) i = table[i];
        }
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    double ans = 0;
    for (int i = 0; i < n; i++) {
        double a;
        string b;
        cin >> a >> b;
        if (b == "BTC")a *= 380000.0;
        ans += a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	list<int> a;
	int q;
	cin>>q;
	list<int>::iterator itr = a.end();
	for(int i = 0; i < q; i++){
		int p;
		cin>>p;
		if(p==0){
			int x;
			cin>>x;
			itr = a.insert(itr,x);
		}else if(p==1){
			int d;
			cin>>d;
			for(int j = 0; j < abs(d); j++){
				if(d>0) itr++;
				else itr--;
			}
		}else{
			itr = a.erase(itr);
		}
	}

	for(list<int>::iterator itr2 = a.begin(); itr2 != a.end(); ++itr2){
		cout << *itr2 << endl;
	}

	return 0;
}


Measured memory_bytes: 18628
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <unordered_map>
using namespace std;
struct point{
    int x;
    int y;
}points[10];
int main(){
    int N,x,y;
    double d=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d %d",&x,&y);
        points[i].x=x;
        points[i].y=y;
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            d+=sqrt((points[i].x-points[j].x)*(points[i].x-points[j].x)+(points[i].y-points[j].y)*(points[i].y-points[j].y));
        }
    }
    printf("%f",2*d/N);
    //cout<<2*d/N<<endl;
}

Measured memory_bytes: 256
import math
a,b,x = map(int,input().split())
if 2 * x >= a * a * b:
    num = a * a * b-x
    num /= a**2
    num *= 2
    print(math.degrees(math.asin(num/math.sqrt(a**2+num**2))))
else:
    x /= a * b
    x *= 2
    print(90-math.degrees(math.asin(x/math.sqrt(x**2+b**2))))

Measured memory_bytes: 3060
a=[None]*3
for i in range(3):
    a[i] = list(map(int,input().split()))
n = int(input())
b=[0]*n
for i in range(n):
    b[i] = int(input())

ans=0

cands =[]
for i in range(3):
    cand = a[i]
    cands.append(cand) 

for i in range(3):
    cand=[a[j][i] for j in range(3)]
    cands.append(cand) 

        
cand = [ a[i][i] for i in range(3)]
cands.append(cand) 

cand = [ a[i][2-i] for i in range(3)]
cands.append(cand) 

ans=0
for c in cands:
    ans0=[(cc in b) for cc in c]
    if sum(ans0) ==3:
        ans=1
    
if ans==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
import sys

S = input()
C_count = 0
flag = True

if(S[0] == 'A'):
  for i in range(2, len(S)-1):
    if(S[i] == 'C'):
      C_count += 1
      C_i = i
  if(C_count == 1):
    for i in range(1, len(S)):
      if(i != C_i):
        if(S[i].isupper()):
          flag = False
    if(flag):
      print("AC")
      sys.exit()
print("WA")


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
long mod=998244353,dp[301][90001],dp2[301][90001];
long ans=1;
int N,a[300],SUM;
main()
{
	cin>>N;
	dp[0][0]=dp2[0][0]=1;
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
		SUM+=a[i];
		for(int k=0;k<=SUM-a[i];k++)
		{
			(dp[i+1][k+a[i]]+=dp[i][k])%=mod,(dp[i+1][k]+=dp[i][k]*2)%=mod;
			(dp2[i+1][k+a[i]]+=dp2[i][k])%=mod,(dp2[i+1][k]+=dp2[i][k])%=mod;
		}
		ans=ans*3%mod;
	}
	for(int i=(SUM+1)/2;i<=SUM;i++)
	{
		ans=(ans-dp[N][i]*3%mod+mod)%mod;
	}
	if(SUM%2==0)
	{
		ans=(ans+dp2[N][SUM/2]*3%mod)%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 421504
#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define ll long long
#define pb push_back
#define mkp make_pair
#define inf 1e9
#define rn 100007
#define ppi pair<int,int>
#define mod 1000000007

int n,k,ara[100007],dp[100007];
int fun(int ind)
{
    if(ind>=n-1)return 0;
    if(dp[ind]!=-1)return dp[ind];
    int mn=inf;
    for(int i=1;i<=k;i++)
        if(ind+i<n)
        mn=min(mn,fun(ind+i)+abs(ara[ind+i]-ara[ind]));
    return dp[ind]=mn;
}
int main()
{
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
        cin>>ara[i];
    cout<<fun(0)<<endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define int long long
#define Mod 998244353
using namespace std;
int Read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')  f = -1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}
int n, k, addv[800005], sum[800005], l[55], r[55], f[200005];
void pusha(int o, int l, int r, int x) {
	addv[o] += x; addv[o] %= Mod;
	sum[o] += (r - l + 1) * x % Mod;  sum[o] %= Mod;
}
void pushdown(int o, int l, int r) {
	int mid = (l + r) >> 1;
	if(addv[o]) {
		pusha(o << 1, l, mid, addv[o]);
		pusha(o << 1 | 1, mid + 1, r, addv[o]);
		addv[o] = 0;
	}
}
void modify(int o, int l, int r, int nl, int nr, int x) {
	if(nl <= l && r <= nr) {
		pusha(o, l, r, x);
		return ;
	}
	int mid = (l + r) >> 1;
	pushdown(o, l, r);
	if(nl <= mid)  modify(o << 1, l, mid, nl, nr, x);
	if(mid < nr)  modify(o << 1 | 1, mid + 1, r, nl, nr, x);
	sum[o] = sum[o << 1] + sum[o << 1 | 1];
	sum[o] %= Mod;
}
int query(int o, int l, int r, int pos) {
	if(l == r)  return sum[o];
	int mid = (l + r) >> 1;
	pushdown(o, l, r);
	if(pos <= mid)  return query(o << 1, l, mid, pos);
	else  return query(o << 1 | 1, mid + 1, r, pos);
}
signed main() {
	n = Read(), k = Read();
	for(int i = 1; i <= k; i++)
		l[i] = Read(), r[i] = Read();
	for(int i = 1; i <= n; i++) {
		if(i == 1)  f[1] = 1;
		else  f[i] = query(1, 1, n, i);
		for(int j = 1; j <= k; j++) {
			int L = i + l[j], R = i + r[j];
			if(L > n)  continue;
			if(R > n)  R = n;
			modify(1, 1, n, L, R, f[i]);
		}
	}
	cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 13248
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    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())

N, M = list(map(int, input().split()))
u = UnionFind(N)
for i in range(M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    u.union(a, b)
n_size = 0
for i in range(N):
    n_size = max(n_size, u.size(i))
print(n_size)

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

class unionFind{
    template<typename T>
    using vector = std::vector<T>;

    vector<int> par;
    vector<long long> wei;
    int groupCount;

public:
    void init(int n = 0){
        par.resize(n);
        fill(par.begin(), par.end(), -1);

        wei.resize(n);
        fill(wei.begin(), wei.end(), 0LL);

        groupCount = n;

        return;
    }

    unionFind(int n = 0){
        init(n);
    }

    int root(int x){
        if(par[x] < 0){
            return x;
        }
        int r = root(par[x]);
        wei[x] += wei[par[x]];
        return par[x] = r;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return -par[root(x)];
    }

    long long weight(int x){
        root(x);
        return wei[x];
    }

    long long diff(int x, int y){
        if(!same(x, y)){
            return LLONG_MIN;
        }
        return weight(y) - weight(x);
    }

    bool unite(int x, int y, long long w = 0){
        w += weight(x) - weight(y);

        x = root(x);
        y = root(y);

        if(x == y){
            return false;
        }

        if(size(x) < size(y)){
            std::swap(x, y);
            w = -w;
        }

        par[x] += par[y];
        par[y] = x;
        wei[y] = w;
        --groupCount;

        return true;
    }

    int number_of_group(void){
        return groupCount;
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<lint> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    lint now = n * (n - 1LL) / 2LL;
    vector<lint> ans(m);
    unionFind uf(n);
    rrep(i, m){
        ans[i] = now;
        lint as = uf.size(a[i]), bs = uf.size(b[i]);
        if(uf.unite(a[i], b[i])){
            now -= as * bs;
        }
    }

    rep(i, m){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

// struct ---------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    ll st = a * 60 + b, ed = c * 60 + d;
    cout << max(0ll, (ed - st - e)) << endl;
    return 0;
}


Measured memory_bytes: 3632
N = int(input())
st = []
st.append([list(map(str, input().split())) for _ in range(N)])
X = str(input())
ans = 0

for i in range(N):
  st[0][i][1] = int(st[0][i][1])
  
flag = 0

for i in range(N):
  if flag == 0:
    if st[0][i][0] == X:
      flag = 1
  else:
    ans += st[0][i][1]
    
print(ans)

Measured memory_bytes: 3316
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int sx,sy,tx,ty;

main(){
	cin>>sx>>sy>>tx>>ty;
	int a=ty-sy;
	int b=tx-sx;
	rep(i,a)cout<<'U';
	rep(i,b)cout<<'R';
	rep(i,a)cout<<'D';
	rep(i,b)cout<<'L';
	cout<<'L';
	rep(i,a+1)cout<<'U';
	rep(i,b+1)cout<<'R';
	cout<<'D';
	cout<<'R';
	rep(i,a+1)cout<<'D';
	rep(i,b+1)cout<<'L';
	cout<<'U'<<endl;
}

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

using namespace std;

const int L = 100000 + 1;

void calc(vector<vector<int>>& cache, int x, int n, const vector<int>& table, const vector<int>& Vs, const vector<int>& Ws){
	if(x <= n){
		const auto v = Vs[x - 1];
		const auto w = Ws[x - 1];
		vector<int> new_table = table;
		for(int w0 = L - 1; w0 >= 0; w0--){
			const int w1 = w0 + w;
			const int v1 = new_table[w0] + v;
			if(w1 <= L && new_table[w1] < v1){
				new_table[w1] = v1;
			}
		}
		calc(cache, x * 2, n, new_table, Vs, Ws);
		calc(cache, x * 2 + 1, n, new_table, Vs, Ws);
		cache[x - 1] = move(new_table);
	}
}

int main(void){
	int N;
	cin >> N;
	vector<int> Vs(N);
	vector<int> Ws(N);
	for(int i = 0; i < N; i ++){
		cin >> Vs[i];
		cin >> Ws[i];
	}
	
	const int n = N < 1024 ? N : 1024;

	vector<vector<int>> cache(n);

	calc(cache, 1, n, vector<int>(L, 0), Vs, Ws);
	
	int Q;
	cin >> Q;
	for(int q = 0; q < Q; q ++){
		int i, l;
		cin >> i;
		cin >> l;
		if(i <= n){
			cout << cache[i - 1][l] << endl;
		}else{
			int j = i;
			vector<int> target_vs(0);
			vector<int> target_ws(0);
			while(j > n){
				target_vs.push_back(Vs[j - 1]);
				target_ws.push_back(Ws[j - 1]);
				j /= 2;
			}
			const vector<int>& table = cache[j - 1];
			int topvalue = 0;
			int b_max = 1;
			for(int k = 0; k < target_ws.size(); k ++){
				b_max *= 2;
			}
			for(int b = 0; b < b_max; b ++){
				int v0 = 0;
				int w0 = 0;
				int x = 0;
				int b2 = b;
				while(b2 > 0){
					if(b2 % 2 == 1){
						v0 += target_vs[x];
						w0 += target_ws[x];
					}
					x += 1;
					b2 /= 2;
				}
				if(w0 <= l){
					int v1 = v0 + table[l - w0];
					if(v1 > topvalue){
						topvalue = v1;
					}
				}
			}
			cout << topvalue << endl;
		}
	}
	return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> S[i][j];
        }
    }
    int res=0;
    int dx[4]={1, 0, -1, 0};
    int dy[4]={0, 1, 0, -1};
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            queue<pii> que;
            vector<vi> dist(H, vi(W, -1));
            que.push({i, j});
            dist[i][j]=0;
            while(!que.empty()){
                int x, y;
                tie(x, y)=que.front();
                que.pop();
                for(int i=0; i<4; i++){
                    int nx=x+dx[i];
                    int ny=y+dy[i];
                    if(nx<0 || nx>=H || ny<0 || ny>=W) continue;
                    if(dist[nx][ny] != -1 || S[nx][ny] == '#') continue;
                    dist[nx][ny]=dist[x][y]+1;
                    res=max(res, dist[nx][ny]);
                    que.push({nx, ny});
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif

    string s;
    cin>>s;
    int n= s.size();

    for(int i=0;i<n;++i) {
        if(s[i] == '?') {
            s[i] = 'D';
        }
    }

    cout<<s<<"\n";

    return 0;
}

Measured memory_bytes: 3780
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

ll N;
vector<ll> A, B, C;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  B.resize(N);
  for (ll i = 0; i < N; i++) {
    cin >> B[i];
  }
  sort(B.begin(), B.end());
  C.resize(N);
  for (ll i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(C.begin(), C.end());

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll bi = B[i];
    ll a_num = lower_bound(A.begin(), A.end(), bi) - A.begin();
    ll c_num = N - (upper_bound(C.begin(), C.end(), bi) - C.begin());
    ans += (a_num * c_num);
  }

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[55],c[55];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    double ans=((double)a[1]+(double)a[2])/2.0;
    for(int i=3;i<=n;i++){
        ans=(ans+(double)a[i])/2.0;
    }
    printf("%.10f\n",ans);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	double r;
	cin >> r;
	cout << fixed << setprecision(6) << r*r*M_PI << " " << fixed << setprecision(6) << 2 * M_PI*r << "\n";

	return 0;
}

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

int main() {
  int x,a,b;cin>>x>>a>>b;
  cout << (x-a)%b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,c=0;
	cin>>n;
	int l[1000],r[1000];
	for(int i=0;i<n;i++){
		cin>>l[i]>>r[i];
		c+=r[i]-l[i]+1;
	}
	cout<<c<<endl;
	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int k;
	string s;
	cin >> k >> s;

	if(s.size() <= k){
		cout << s << endl;
		return 0;
	}
	cout << s.substr(0, k) << "..." << endl;
	return 0;
}

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

const int MAX_N = 100000 + 1000;
namespace DSU{
  int p[MAX_N];
  
  void init() {
    for ( int i = 0 ; i < MAX_N ; i++ ) p[i] = i;
  }
  
  int Find ( int v ) {
    if ( v != p[v] ) p[v] = Find ( p[v] );
    return p[v];
  }
  
  void Merge ( int a , int b ) {
    a = Find ( a ) ;
    b = Find ( b );
    if ( a == b ) return;
    p[b] = a;
  }
  
};



struct Data{
  int id;
  int cnt;
  
  inline bool operator < ( const Data&foo ) const {
    if ( cnt != foo.cnt ) return ( cnt > foo.cnt );
    return ( id < foo.id );
  }
};

Data make_data ( int id , int cnt ) {
  Data res;
  res.id = id;
  res.cnt = cnt;
  return res;
}


void Insert ( multiset<int>& Fst , multiset<int>&Sec ) {
  for ( auto x : Sec ) {
    Fst.insert ( x );
  }
}

int a[MAX_N];

multiset<int> Values[MAX_N];
int sizes[MAX_N];



int main() {
  
  DSU::init();
  
  long long ans = 0;
  
  vector<Data> vv;
  
  int n , m;
  scanf ("%d %d" , &n , &m );
  
  for ( int i = 1 ; i <= n ; i++ ) {
    scanf ( "%d" , &a[i] );
  }
  
  for ( int i = 0 ; i < m ; i++ ) {
    int a , b;
    scanf ( "%d %d" , &a , &b );
    a++;
    b++;
    DSU::Merge ( a , b );
  }
  
  for ( int i = 1 ; i <= n ; i++ ) {
    Values[ DSU::Find(i) ].insert ( a[i] );
    sizes [ DSU::Find(i) ] += 1;
  }
  
  for ( int i = 1 ; i <= n ; i++ ) {
    if ( DSU::Find ( i ) == i ) {
      vv.push_back ( make_data ( i , sizes[i] ) );
    }
  }
  
  sort ( vv.begin() , vv.end() );
  bool fail = false;
  
  int fst = -1;
  
  for ( auto x : vv ) {
    if ( fst == -1 ) {
      fst = x.id;
    }
    else {
      
      if ( Values[fst].empty() ) {
        fail = true;
        break;
      }
      
      auto it = Values[fst].begin();
      ans += *it;
      Values[fst].erase ( it );
      
      it = Values[ x.id ].begin();
      ans += *it;
      Values[x.id].erase ( it );
      
      DSU::Merge ( fst , x.id );
      // Merge fst and x.id sets
      
      if ( Values[fst].size() >= Values[ x.id ].size() ) {
        //Values[fst].insert ( Values[x.id] );
        Insert ( Values[fst] , Values[x.id] );
      }
      else {
        //Values[x.id].insert ( fst );
        Insert ( Values[x.id] , Values[fst] );
        fst = x.id;
      }
      
    }
  }
  
  
  
  
  
  for ( int i = 1 ; i <= n ; i++ ) {
    if ( DSU::Find(1) != DSU::Find(i) ) fail = true;
  }
  
  if ( fail ) {
    printf ( "Impossible\n" );
  }
  else {
    printf ( "%lld\n" , ans );
  }

  return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  int64 t;
  cin >> n >> t;
  t += 1;

  vector<tuple<int64, int64>> items;
  vector<int64> xs;
  for (int i = 0; i < n; i++) {
    int64 a, b;
    cin >> a >> b;
    a += 1;
    b += 1;
    if (a == 1) {
      xs.push_back(b);
    } else {
      items.push_back(make_tuple(a, b));
    }
  }
  sort(xs.begin(), xs.end());
  sort(items.begin(), items.end(),
       [](const tuple<int64, int64>& t1, const tuple<int64, int64>& t2) {
    int64 a1, b1, a2, b2;
    tie(a1, b1) = t1;
    tie(a2, b2) = t2;
    return (a1 - 1) * b2 > b1 * (a2 - 1);
  });

  constexpr int T = 50;
  constexpr int64 INF = 2E9;
  vector<int64> dp(T + 1, INF);
  dp[0] = 1;
  for (int i = 0; i < items.size(); i++) {
    int64 a, b;
    tie(a, b) = items[i];
    for (int k = T - 1; k >= 0; k--) {
      if (dp[k] < INF) {
        if (dp[k] * a + b < dp[k + 1]) {
          dp[k + 1] = dp[k] * a + b;
        }
      }
    }
  }

  int g_ans = 0;
  for (int k = 0; k <= T; k++) {
    if (dp[k] <= t) {
      int ans = k;
      int64 c = dp[k];
      for (int i = 0; i < xs.size(); i++) {
        if (c + xs[i] <= t) {
          c += xs[i];
          ans++;
        }
      }
      g_ans = max(g_ans, ans);
    }
  }
  cout << g_ans << endl;
}

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

int64_t MOD = 1000000000 + 7;

int64_t f1(int64_t X, int64_t a) {
  if(a == 0) {
    return 1;
  }
  else if(a % 2 == 0) {
    int64_t ans = f1(X, a / 2) * f1(X, a / 2);
    ans %= MOD;
    return ans;
  }
  else {
    int64_t ans = f1(X, a / 2) * f1(X, a / 2);
    ans %= MOD;
    ans *= X;
    ans %= MOD;
    return ans;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  for(int i = 1; i <= K; i++) {
    if(N - K < i - 1) {
      cout << 0 << endl;
    }
    else {
      int64_t ans = 1;
      for(int64_t j = 1; j <= i - 1; j++) {
        ans *= K - j;
        ans %= MOD;
      }
      int64_t X = 1;
      for(int64_t j = 1; j <=  i - 1; j++) {
        X *=  j;
        X %= MOD;
      }
      ans *= f1(X, MOD - 2);
      ans %= MOD;
      for(int64_t j = 0; j < i; j++) {
        ans *= N - K + 1 - j;
        ans %= MOD;
      }
      int64_t Y = 1;
      for(int64_t j = 1; j <= i; j++) {
        Y *= j;
        Y %= MOD;
      }
      ans *= f1(Y, MOD - 2);
      ans %= MOD;
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3508
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;


int main()
{
    int N;
    cin >> N;
    map<int, int> a;
    for(int i = 0; i < N; ++i){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    int sum = 0;
    for(auto& t : a){
        t.second--;
        sum += t.second;
    }

    if(sum % 2 == 0){
        cout << N - sum << endl;
    }else{
        cout << N - sum - 1 << endl;

    }


    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[5];
        for (int i = 0; i < 5; i++) {
            A[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        int max = A[4] - A[0];
        if (max <= k) System.out.println("Yay!");
        else System.out.println(":(");
        sc.close();
    }
}

Measured memory_bytes: 21844
from math import floor, ceil
N = int(input())
A = []
for i,a in enumerate(input().split()):
  A.append(int(a)-(i+1))
A.sort()
if N % 2 :
    print(-1*sum(A[:N//2]) + sum(A[N//2+1:]))
else:
    print(-1*sum(A[:N//2]) + sum(A[N//2:]))


Measured memory_bytes: 26832
#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>;

const ll mod=1e9+7;

int main(){
    int n;
    cin>>n;

    //0~9
    ll all=1;
    rep(i, n){
        all=(all*10)%mod;
    }

    //0~8
    ll all_a=1;
    rep(i, n){
        all_a=(all_a*9)%mod;
    }

    //1~9
    ll all_b=1;
    rep(i, n){
        all_b=(all_b*9)%mod;
    }

    //1~8
    ll all_c=1;
    rep(i, n){
        all_c=(all_c*8)%mod;
    }

    all+=ll(mod*3);
    ll ans=(all-all_a-all_b+all_c)%mod;
    if(n==1) ans=0;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <unordered_map>
using namespace std;


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

  unordered_map<int, int> num2count;
  int a;
  long long S = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    S += a;
    auto it = num2count.find(a);
    if (it == num2count.end()) num2count[a] = 1;
    else it->second++;
  }

  int Q;
  cin >> Q;
  int b, c;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    auto itB = num2count.find(b);
    auto itC = num2count.find(c);
    if (itB == num2count.end()) {
      cout << S << endl;
    } else {
      if (itC == num2count.end()) num2count[c] = itB->second;
      else itC->second += itB->second;
      S += (c - b) * itB->second;
      itB->second = 0;
      cout << S << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6656