akhauriyash/Code-Regression huggingface dataset:
n=int(input())
b=[[]for _ in range(n)]
d=[]
inf=float('inf')
inf=float('inf')
for i in range(n):
  s=input()
  c=[]
  for j in range(n):
    if s[j]=="1":
      b[i]+=[(i,j)]
    c.append(1 if s[j]=="1" else inf)
  d.append(c)
def warshall_floyd(d):
    for i in range(n):d[i][i]=0
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=warshall_floyd(d)
x=[-1]*n
x[0]=0
Q=b[0]
while Q:
  p=[]
  for i,j in Q:
    if x[j]<0:
      x[j]=x[i]^1
      p+=b[j]
    elif x[i]==x[j]:print(-1);exit()
  Q=p
z=0
for i in d:
  for j in i:
    if j!=float("inf"):z=max(j,z)
print(z+1)

Measured memory_bytes: 56284
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int a[3];
	FOR(3) cin >> a[i];
	sort(a,a+3);
	cout << a[0] + a[1];
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S;
	cin >> S;

	int kazu = 0;

	int temp = 0;
	int worst = 0;

	rep(i, S.size()) {
		if (S[i] == '(') {
			kazu++;
			temp++;
		}
		else {
			temp--;
		}
		worst = min(worst, temp);
	}

	kazu = kazu * 2 - S.size();

	if (kazu < 0) worst -= kazu;

	string Smae, Sato;

	rep(i, -kazu) Smae += "(";
	rep(i, kazu) Sato += ")";
	rep(i, -worst) Smae += "(";
	rep(i, -worst) Sato += ")";

	co(Smae + S + Sato);

	Would you please return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int max_v = max(max(a, b), c);
    vector<int> v(3);
    v[0] = a; v[1] = b; v[2] = c;
    sort(v.begin(), v.end());

    int count = 0;
    int diff1 = v[2] - v[1];
    count += diff1;
    v[1] += diff1;
    v[0] += diff1;

    int diff2 = v[2] - v[0];
    if(diff2 == 1){
        count += 2;
    }
    else if(diff2 == 0){
        //
    }
    else {
        if(diff2 % 2 == 0){
            count += diff2 / 2;
        }
        else {
            count += diff2 / 2 + 2;
        }
    }

    cout << count << endl;


}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int h, w;
	cin >> h >> w;
	rep(i, w+2) cout << '#';
	cout << endl;
	rep(i, h){
		string s;
		cin >> s;
		cout << '#' << s << '#' << endl;
	}
	rep(i, w+2) cout << '#';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
using namespace std;
struct edge{int x, y, next;}a[N*2];
int n, l, p[N], x, y, du[N], flag[N], sum, s[N], op, cl, d[N], b[N], c[N];
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
int main(){
	scanf("%d", &n);
	l=0; memset(p, 0, sizeof(p)); memset(du, 0, sizeof(du));
	for(int i=1; i<=n-1; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x); du[x]++; du[y]++;}
	memset(flag, 0, sizeof(flag)); sum=n;
	memset(s, 0, sizeof(s));
	op=cl=0; for(int i=1; i<=n; i++){if(du[i]==1)d[++cl]=i; if(!du[i]){printf("First"); return 0;}}
	while(sum){
		l=0; while(op<cl){op++; b[++l]=d[op]; for(int j=p[d[op]]; j; j=a[j].next)if(!flag[a[j].y])c[l]=a[j].y;}
		for(int i=1; i<=l; i++)if(c[i]){s[c[i]]++; if(s[c[i]]>=2){printf("First"); return 0;}}
		for(int i=1; i<=l; i++){flag[b[i]]=1; sum--;}
		for(int i=1; i<=l; i++)if(!flag[c[i]]){flag[c[i]]=1; sum--;}
		for(int i=1; i<=l; i++)
			for(int j=p[c[i]]; j; j=a[j].next)if(!flag[a[j].y]){
				du[a[j].y]--; if(!du[a[j].y]){printf("First"); return 0;}
				if(du[a[j].y]==1)d[++cl]=a[j].y;
			}
	}
	printf("Second");
	return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
using namespace std;
 
int b[1000];
 
int main(){
    int y[2][6];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a[6];
    int MAX;
    
    for(int i=0;i<2;i++){
        for(int j=0;j<6;j++){
            cin>>y[i][j];
            b[y[i][j]] ++;
        }
    }
    for(int i=0;i<1000;i++){
        MAX=max(MAX,b[i]);
    }
    if(MAX>=6){
        cout<<"Yes"<<endl;
        goto Exit;
    }
    for(int i=0;i<6;i++){
        for(int j=0;j<6;j++){
            if(y[0][j]==y[1][i]){
                a[i]=j;
            }
        }
    }
    if(x[a[0]][a[1]]==a[2]+1){
        cout<<"Yes"<<endl;
        goto Exit;
    }
    cout<<"No"<<endl;
    Exit:;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
using namespace std;
int N, sp, pl, pr, ql, qr, que[14348915]; long long D, ret, X[33], Y[33], ax[14348915], ay[14348915], bx[14348915], by[14348915], tx[4782977], ty[4782977];
int main() {
	cin >> N >> D; sp = N / 2;
	for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
	long long lm = 1;
	for (int i = 0; i < sp; i++) {
		for (int j = 0; j < lm; j++) tx[j] = ax[j], ty[j] = ay[j]; tx[lm] = 1LL << 60;
		int ap = 0, bp = 0, cp = 0;
		for (int j = 0; j < lm * 3; j++) {
			long long av = tx[ap] - X[i], bv = tx[bp], cv = tx[cp] + X[i];
			if (av <= bv && av <= cv) ax[j] = av, ay[j] = ty[ap++] - Y[i];
			else if (bv <= cv) ax[j] = bv, ay[j] = ty[bp++];
			else ax[j] = cv, ay[j] = ty[cp++] + Y[i];
		}
		lm *= 3;
	}
	long long rm = 1;
	for (int i = sp; i < N; i++) {
		for (int j = 0; j < rm; j++) tx[j] = bx[j], ty[j] = by[j]; tx[rm] = 1LL << 60;
		int ap = 0, bp = 0, cp = 0;
		for (int j = 0; j < rm * 3; j++) {
			long long av = tx[ap] - X[i], bv = tx[bp], cv = tx[cp] + X[i];
			if (av <= bv && av <= cv) bx[j] = av, by[j] = ty[ap++] + Y[i];
			else if (bv <= cv) bx[j] = bv, by[j] = ty[bp++];
			else bx[j] = cv, by[j] = ty[cp++] - Y[i];
		}
		rm *= 3;
	}
	for (int i = 0; i < lm; i++) {
		while (pr != rm && bx[pr] - ax[i] <= D) {
			while (ql != qr && by[pr] >= by[que[qr - 1]]) qr--;
			que[qr++] = pr++;
		}
		while (pl != rm && ax[i] - bx[pl] > D) {
			if (ql != qr && que[ql] == pl) ql++;
			pl++;
		}
		if (ql != qr) ret = max(ret, ay[i] + by[que[ql]]);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 537204
N = int(input())
W = [None] * N

for i in range(N):
    W[i] = input()

ans = "Yes"

for i in range(1, N):
    if W[i - 1][-1] != W[i][0] or W.count(W[i]) >= 2:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1LL<<60

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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

    vector<double> x(N), y(N);
    vector<vector<double>> dist(N, vector<double>(N));
    REP(i, N) cin >> x[i] >> y[i];

    double mean_dist;
    REP(i, N)
        REP(j, N) {
            if(i < j)
                mean_dist += sqrt( pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2) );
        }

    mean_dist /= double(N*(N-1)/2);
    printf("%.16f", (N-1) * mean_dist );

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a,b,c,d,e,k;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
	if(b-a <= k && c-a <= k && d-a <= k && e-a <= k && c-b <= k && d-b <= k && e-b <= k && d-c <= k && e-c <= k && e-d <= k) printf("Yay!\n");
	else printf(":(\n");	

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

int n,x,y;
string ans[] = { "Borys" , "Alice" };

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> x >> y;
    cout << ans[ (y-x-1)%2 ];

    return 0;
}


Measured memory_bytes: 256
import sys

stack = []

array = sys.stdin.readline().strip().split(" ")

for op in array:
    if op.isdigit():
        stack.append(int(op))
    else:
        tmp1 = stack.pop()
        tmp2 = stack.pop()
        if op == "+":
            stack.append(tmp1 + tmp2)
        elif op == "-":
            stack.append(tmp2 - tmp1)
        elif op == "*":
            stack.append(tmp1 * tmp2)
        elif op == "/":
            stack.append(float(tmp2) / tmp1)
res = stack.pop()
print str(int(res))

Measured memory_bytes: 6440
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int N;
    vector<long long> A;
    long long ans = 0;
    
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
        long long t;
        cin >> t;
        A.push_back(t);
    }
    
    for ( int i = 0; i < N; i++ ) {
        
        if ( A[i] <= 2 ) { continue; }
        
        if ( A[i]%2 == 0 ) {
            ans += (A[i]-2)/2;
            A[i] -= A[i] - 2;
        }
        else {
            ans += (A[i]-1)/2;
            A[i] -= A[i] - 1;
        }
    }
    
    for ( int i = 0; i < N; i++ ) {
        
        if ( A[i] == 1 && i != N-1 && A[i+1] ) {
            A[i+1]--;
            ans++;
        }
        if ( A[i] == 2 ) {
            ans++;
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#define NIL -1
using namespace std;

struct Node {
    int parent;
    int child;
    int bro;
    int kk;
};

void get_depth(Node T[], int depth[], int u, int p);
void get_children(Node T[], int children[], int i);

int main(){
    int n;
    cin >> n;
    Node T[n];
    int depth[n];
    int children[n];
    for (int i = 0; i < n; i++){
        T[i].parent = NIL;
        T[i].child = NIL;
        T[i].bro = NIL;
    }
    int id, k;
    for (int i = 0; i < n; i++){
        cin >> id >> k;
        T[id].kk = k;
        int c[k];
        for (int j = 0; j < k; j++) {
            cin >> c[j];
            T[c[j]].parent = id;
            if (j)
                T[c[j - 1]].bro = c[j];
            else
                T[id].child = c[j];
        }
    }
    int r;
    for (int i = 0; i < n; i++){
        if (T[i].parent == NIL)
            r = i;
    }
    get_depth(T, depth, r, 0);
    for (int i = 0; i < n; i++){
        cout << "node " << i << ": parent = ";
        cout << T[i].parent << ", depth = ";
        cout << depth[i] << ", ";
        if (T[i].parent == NIL)
            cout << "root, [";
        else if (T[i].child == NIL)
            cout << "leaf, [";
        else
            cout << "internal node, [";
        if (T[i].child == NIL)
            cout << ']' << endl;
        else {
            get_children(T, children, i);
            for (int j = 0; j < T[i].kk - 1; j++) {
                cout << children[j] << ", ";
            }
            cout << children[T[i].kk - 1] << ']' << endl;
        }
    }
    return 0;
}

void get_depth(Node T[],int depth[], int u,int p){
    depth[u] = p;
    if (T[u].bro != NIL)
        get_depth(T, depth, T[u].bro, p);
    if (T[u].child != NIL)
        get_depth(T, depth, T[u].child, p + 1);
}

void get_children(Node T[], int children[], int i){
    int cnt = 0;
    int c = T[i].child;
    children[cnt] = c;
    while (T[c].bro != NIL){
        cnt++;
        children[cnt] = T[c].bro;
        c = T[c].bro;
    }
}


Measured memory_bytes: 10112
n = int(input())
a = list(map(int, input().split()))
a.sort()
def solve(i):
    size = sum(a[:i+1])
    for j in range(i+1, n):
        if a[j]>2*size:
            return False
        size += a[j]
    return True

ok = n-1
ng = -1
while abs(ok-ng)>1:
    mid = (ok+ng)//2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(n-ok)

Measured memory_bytes: 14252
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
typedef long long int ll;


bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}
// use case
//sort(V.begin(), V.end(), compare_function);

void solve(int a, int b, int c, int k) {
int ats=0;
if (k>0) {
int p=min(a,k);
ats=ats+p;
k=k-p;
}
if (k>0) {
int p=min(b,k);
k=k-p;
}
if (k>0) {
int p=min(c,k);
ats=ats-p;
k=k-p;
}
cout<<ats<<endl;
return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    solve(a,b,c,k);
    return 0;
}


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

dp =  [float("inf")]  * n 
dp[0] = 0

for i in range(0, n - 1):
    if a[i  + 1] < a[i]:
        dp[i + 1] = dp[i] + (a[i] - a[i +1])
        a[i + 1] = a[i]
    else:
        dp[i + 1] = dp[i]
res = dp[n - 1]
print(res)

Measured memory_bytes: 32252
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int N, K;cin >> N >> K;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  vector<bool> dp(K + 1, false);
  rep(i, K + 1) {
    rep(j, N) {
      if(i - a[j] >= 0) dp[i] = dp[i] | !dp[i - a[j]];
    }
  }
  if(dp[K]) cout << "First" << endl;
  else cout << "Second" << endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#define LL long long
LL C(int n,int m)
{
	if(m>n) return 0;
	LL ret=1;
	for(int i=1,j=n;i<=m;j--,i++)
		ret=ret*j/i;
	return ret;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	LL c1=n/k;
	LL ans=c1+C(c1,2)*6+C(c1,3)*6;
	if(k%2==0)
	{
		int k1=k/2;
		LL c2=n/k1-c1;
		ans+=c2+C(c2,2)*6+C(c2,3)*6;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    long double ans = 1;
    bool ok = 0;
    for(int i=1;i<=n;i++){
        long long a;
        scanf("%lld", &a);
        if(a == 0) ok = 1;
        ans *= a;
        if(ans > 1e18){
            ans = 1e19;
        }
    }
    if(ans == 1e19) ans = -1;
    if(ok) printf("0\n");
    else printf("%.0Lf\n", round(ans));
}

Measured memory_bytes: 3872
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int64 n, k;
int64 a[200005], b[200005];

int64 calc(int64 val){
    int64 res = 0;
    for (int i = 0; i < n; i++){
        res += max(0ll, a[i] - val / b[i]);
    }
    return res;
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    sort(a, a + n);
    sort(b, b + n, greater <int64>());
    int64 l = 0, r = 1e13;
    while (l < r){
        int64 mid = (l + r) >> 1;
        if (calc(mid) <= k) r = mid;
        else l = mid + 1;
    }
    cout << l;
    return 0;
}


Measured memory_bytes: 3328
#pragma GCC optimize("O2,unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
int maxn = 531441, B, C;
int n, p[531441], f[531441];
int rev(int a) {
	int r = 0, c = 1;
	while(c < maxn) {
		if(a%3) r +=(3 - (a%3))*c;
		c*=3,a/=3;
	}
	return r;
}

int s = 0;
vector<int> small[729];
int id[531441], lup[531441], u = 0;

void add() {
	s = (s + B - 1)%B;
	for(auto i : small[s]) {
		if(lup[i] != u) {
			if((lup[i]^u)&1) id[i] = f[id[i]];
			lup[i] = u;
		}
		id[i] = (id[i] + 1)%C;
	}
}

void flip() {
	u++;
	for(int i = 0; i < B; i++) {
		if(f[i] <= i) {
			swap(small[(s+i)%B], small[(s+f[i])%B]);
		}
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	string t;
	cin >> n >> t;
	maxn = B = 1;
	for(int i = 0; i < n; i++) maxn *= 3;
	for(int i = 0; i < n/2; i++) B *= 3;
	C = maxn/B;
	for(int i = 0; i < maxn; i++) {
		f[i] = rev(i);
		small[i%B].push_back(i);
		id[i] = i/B;
	}
	
	for(auto i : t) {
		if(i == 'R') add();
		else flip();
	}
	for(int i = 0; i < B; i++)
		for(auto j : small[i]) p[j] += (B+i-s)%B;
	for(int i = 0; i < maxn; i++) {
		if(lup[i] != u) {
			if((lup[i]^u)&1) id[i] = f[id[i]];
			lup[i] = u;
		}
		p[i] += B*id[i];
	}
	for(int i = 0; i < maxn; i++) cout << p[i] << " ";
}


Measured memory_bytes: 15512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007LL;
ll n,k,dp[200100],ans;
ll modp(ll a, ll b)
{
	if(b==0)return 1;
	ll u=modp(a, b/2);
	u=(u*u)%MOD;
	if(b&1)return (a*u)%MOD;
	return u;
}
int main()
{
	cin>>n>>k;
	for(ll i=k;i>=1;i--)
	{
		ll ch=k/i; ch=modp(ch, n);
		for(int j=2*i;j<=k;j+=i)
		{
			ch=(ch-dp[j]+MOD)%MOD;
		}
		dp[i]=ch;
		ch=(ch*i)%MOD;
		ans=(ans+ch)%MOD;
	
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4368
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *C = map(int, read().split())

    C.sort()

    ans = 0
    for i in range(N):
        ans = (ans + C[i] * (N - i + 1)) % MOD

    ans = ans * pow(2, 2 * N - 2, MOD) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 110588
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=4:
    if x1<=i:
      x2=i
      x1=i
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    elif x2 <= i < x1:
      x2=i
print(x1*x2)

Measured memory_bytes: 18600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    /** 週利 */
    private static final double INTEREST_WEEK = 0.05;

    /** 繰り上げ単位 */
    private static final int ROUND_UP_UNIT = 1000;

    /** 元金 */
    private static final int PRINCIPAL = 100000;

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(System.in));
        int intInputWeek = Integer.parseInt(bufferedReader.readLine());

        // 借金計算
        double totalDebt = calcDebt(PRINCIPAL, intInputWeek);
        System.out.println((int) totalDebt);
    }

    /**
     * 借金計算メソッド（週利0.05%）
     * @param debt 現在の借金
     * @param week 現在の残り週
     * @return 借金額
     */
    private static double calcDebt(double debt, int week) {
        if (week == 0) {
            return debt;
        }
        debt *= 1 + INTEREST_WEEK;

        // 1000円未満は切り上げる
        double debtPlus = debt / ROUND_UP_UNIT - (int) (debt / ROUND_UP_UNIT);
        if (debtPlus > 0)
            debt = debt + ROUND_UP_UNIT - debtPlus * ROUND_UP_UNIT;

        return calcDebt(debt, --week);
    }

}

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

list = [[0 for i in range(10)] for j in range(12)]

for i in range(n):
	b, f, r, v = map(int, input().split())
	list[3*(b-1)+f-1][r-11] += v
	
for i in range(12):
	for j in range(10):
		print(" {}".format(list[i][j]), end="")
	print()	
	if ((i + 1) % 3) == 0 and i != 11:
		print("#"*20)
	

Measured memory_bytes: 7648
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d))
    {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int a[200000];

int main() {
    int n, i;
    long long sum = 0, sum2 = 0, ans = 1e18;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) sum += a[i];
    
    for (i = 0; i < n; i++) {
        sum2 += a[i];
        
        ans = min(ans, abs(sum - sum2 * 2));
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 896
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for i in range(1, N+1):
    si = str(i)
    d[(si[0], si[-1])] += 1
ans = 0
for i in '123456789':
    for j in '123456789':
        ans += d[(i, j)] * d[(j, i)]
print(ans)

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

int main() {
  int h, m, s, r;

  while (1) {
    cin >> h >> m >> s;
    if (h==-1 && m==-1 && s==-1) break;
    r = 7200 - h*3600 - m*60 - s;
    for (int i=0; i<2; i++) {
      if (i) r *= 3;
      h = r/3600;
      m = (r%3600)/60;
      s = r%60;
      cout.fill('0');
      cout << setw(2) << h << ':';
      cout << setw(2) << m << ':';
      cout << setw(2) << s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1172
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 305
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, sum, a[MAXN], num[4];
LD f[MAXN][MAXN][MAXN];

int main()
{
	scanf("%d", &n);
	for(rint i=1; i<=n; ++i)
	{
		scanf("%d", &a[i]);
		num[a[i]]++; sum+=a[i];
	}
	for(rint x=1; x<=sum; ++x)
	{
		for(rint i=0; i<=x/3; ++i)
		{
			for(rint j=0; j<=(x-i*3)/2; ++j)
			{
				int k=x-i*3-j*2;
				if(i+j+k>n) continue;
				//printf("%d %d %d!!!\n", i, j, k);
				f[i][j][k]=n;
				if(i>0) f[i][j][k]+=i*f[i-1][j+1][k];
				if(j>0) f[i][j][k]+=j*f[i][j-1][k+1];
				if(k>0) f[i][j][k]+=k*f[i][j][k-1];
				f[i][j][k]/=(i+j+k);
				//printf("%d %d %d %Lf!!!\n", i, j, k, f[i][j][k]);
			}
		}
	}
	printf("%.10Lf\n", f[num[3]][num[2]][num[1]]);
	return 0;
}

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

bool chk(int xsum, int a){
  return (xsum & a) == 0;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int l = 0, xsum = 0;
  vector<int> av(n, -1);
  rep(i, n){
    while(1){
      if(chk(xsum, a.at(i)) == true){
        xsum ^= a.at(i);
        break;
      }else{
        av.at(l) = i-l;
        xsum ^= a.at(l);
        l++;
      }
    }
  }
  rep2(i, l, n){
    av.at(i) = n-i;
  }
  ll ans = 0;
  rep(i, n){
    ans += av.at(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4784
N = int(input())
dish = []
for i in range(N):
    a, b = map(int, input().split())
    dish.append((a+b, (a,b)))

# while True:
#     try:
#         a, b = map(int, input().split())
#     except EOFError:
#         break
#     dish.append((a+b, (a,b)))


l = sorted(dish, reverse=True)

t=a = 0
for i, (_, (a_i, b_i)) in enumerate(l):
    if i % 2 == 0:
        #takahashi
        t += a_i
    else:
        a += b_i

print(t-a)


Measured memory_bytes: 27232
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
#define pos first
#define index second
#define mp make_pair
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=2e5+10;
const int maxm=1e2+10;
const int mod=1e9+7;
int n;
char op[10];
int init()
{
    ll k=10;
    for(int i=1;i<=9;i++)
    {
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='N')
            return i;
        k=k*10;
    }
    k=9;
    for(int i=1;i<=9;i++)
    {
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y')
            return i;
        k=k*10+9;
    }
    return 10;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int len=init();
    if(len==10)
    {
        printf("! %lld\n",(ll)1e9);
        return 0;
    }
    ll ans=0;
    for(int i=1;i<len;i++)
    {
        int l=0,r=9,t;
        //if(i==1) l=1;
        t=l;
        while(l<=r)
        {
            int mid=(l+r)/2;
            printf("? %lld\n",ans*10+mid);
            fflush(stdout);
            scanf("%s",op);
            if(op[0]=='Y')
            {
                t=max(t,mid);
                l=mid+1;
            }
            else
                r=mid-1;
        }
        ans=ans*10+t;
    }
    for(int i=(len==1?1:0);i<=9;i++)
    {
        printf("? %lld\n",(ans*10+i)*10);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y')
        {
            ans=ans*10+i;
            break;
        }
    }
    printf("! %lld\n",ans);
    return 0;
}

Measured memory_bytes: 596
//
// Created by Hideaki Imamura on 2020-03-15.
//
# include <bits/stdc++.h>

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

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

# define EPS (1e-7)
//# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, W;
int w[110], v[110];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> w[i] >> v[i];

    const ll INF = 1L << 60;
    vector<ll> dp(1e5 + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 1e5; j >= 0; --j) {
            if (j - v[i] >= 0) chmin(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    ll ans = -1;
    for (ll j = 1e5; j >= 0; --j) {
        if (dp[j] <= W) chmax(ans, j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
fun main (args : Array<String>) {
	val (a, b) = readLine()!!.split(" ")
	val A : Int = a.toInt()
	val B : Int = b.toInt()
	var str : String = ""
	if (A <= B) {
		for (i in 0..B - 1) {
			str += A.toString()
		}
	} else {
		for (i in 0..A - 1) {
			str += B.toString()
		}
	}
	return println("${str}")
}

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



int main() {
  int n, q; cin >> n >> q;
  string str; cin >> str;

  vector<int> l, r;
  l.resize(q);
  r.resize(q);
  for (int i = 0; i < q; i++) cin >> l[i] >> r[i];


  vector<int> v(n+1, 0);
  for (int i = 0; i < n; i++) {
    if (i+1<n && str[i]=='A' && str[i+1]=='C') v[i+1] = v[i] + 1;
    else v[i+1] = v[i];
  }

  for (int i = 0; i < q; i++) {
    cout << v[r[i]-1] - v[l[i]-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){	
	
	int n;
	cin >> n;
	
	vector<int> l(n);
	for(int i=0;i<n;i++)cin >> l[i];
	sort(l.begin(),l.end());
	int ans=0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			int k=l[i]+l[j];
			for(int x=j+1;x<n;x++){
				if(k>l[x]){
					ans++;
				}else{
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main() {
	int n, x, t;
	if (scanf("%d", &n) == 1)
	if (scanf("%d", &x) == 1)
	if (scanf("%d", &t) == 1)

	printf("%d\n", (n % x == 0) ? t * (n / x) : t * ((n / x) + 1));
	return 0;
}



Measured memory_bytes: 1724
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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=1e18;
const double pi=2*acos(0.0);
//abc169e

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];
    V<ll> c(n),d(n);
    rep(i,n){
        c[i]=a[i];
        d[i]=b[i];;
    }
    sort(all(c));
    sort(all(d));
    ll ans=0;
    if(n%2==1){
        ans+=-c[n/2]+d[n/2]+1;
    }else{
        ll x=c[n/2-1];
        ll y=c[n/2];
        ll z=d[n/2-1];
        ll w=d[n/2];
        ll aa=(x+y)/2;
        if((x+y)%2==1){
            aa++;
            ans++;
        }
        ll bb=(z+w)/2;
        if((z+w)%2==1){
            ans++;
        }
        ans+=bb-aa;
        ans+=bb-aa+1;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 9520
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll x;
    cin >> x;

    ll a = x/11;
    ll b = x%11;
    if(b == 0) {
        out(2*a);
    }
    else if(b <= 6) {
        out(2*a + 1);
    }
    else {
        out(2*a + 2);
    }

    re0;
}

Measured memory_bytes: 256
MOD = 10**9+7
N = int(input())
x = list(map(int,input().split()))
x.sort()

kaijo = [1]
for i in range(1,N):
    kaijo.append(kaijo[-1]*i % MOD)

ans = 0
for i in range(N - 1):
    ans = (ans * (i+1) + (x[-1] - x[i]) * kaijo[i]) % MOD

print(ans)

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

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

typedef long long int ll;

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


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

  cout << (N % 500 <= A ? "Yes" : "No") << endl;
}



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

int partition(vector<int> &A, int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];

    int q = partition(A, 0, n - 1);

    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define    common(a,b)      SORT(a), SORT(b), a.erase(set_intersection(all(a),all(b),a.begin()),a.end())
#define    uncommon(a,b)    SORT(a), SORT(b), a.erase(set_symmetric_difference(all(a),all(b),a.begin()),a.end())
#define    minv(v)         *min_element(all(v))
#define    maxv(v)         *max_element(all(v))
#define    SORT(v)          sort(all(v))
#define    REV(x)           reverse(x.begin(),x.end())
#define    all(x)           x.begin(), x.end()
#define    rev(v)           reverse(all(v))
#define    unq(v)           sort(all(v)),v.erase(unique(all(v)),v.end())
#define    fr(i,x,n)        for(int i=x;i<n;i++)
#define    trav(a,x)        for (auto &a: x)
#define    sz(x)            (ll)(x).size()
#define    ll               long long int
#define    pb               push_back
#define    in               insert
#define    gcd(a, b)        __gcd(a, b)
#define    lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define    w(t)              cin>>t;while(t--)
const ll mod = 1000000007;
const double pi = acos(-1.0);
/*bool isprime(int x)
{
    if(x==0 or x==1)return false;
    for(int i=2; i*i<=x; i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}*/
/*ll power(ll n,ll b,ll mod)
{
    ll res=1;
    while(b)
    {
        if(b%2)res=((n%mod)*(res%mod))%mod,b--;
        else n=((n%mod)*(n%mod))%mod,b/=2;
    }
    return res;
}*/
string str[]= {"YES","NO"};
int main()
{
    _ios
    //ll z;
    //w(z)
    //{
        ll n,a,b,c,d,e,x,y,mul=1,cn=0,cn1=0,cn2=0,sm=0,sm1=0,sm2=0,mx=INT_MIN,mx1=INT_MIN,mn=INT_MAX,mn1=INT_MAX,i,j,k=0,temp;
        string s,ss,sss,str="";
        set<ll>st;
        map<ll,ll>mp;
        bool f=true,ff=true;
          cin>>s;
          for(auto i:s)
          {
              sm+=i-'0';
          }
          if(sm==0)cout<<"Yes"<<endl;else
          cout<<(sm%9==0?"Yes":"No")<<endl;
            /*if(a%2==0 and sqrt(a)*sqrt(a)!=
                 a)
               cout<<min(a%2,a/2)<<endl;
              else
                  cout<<max(a%2,a/2+1)<<endl;*/
       // }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	priority_queue<int> Q;
	for(int i = 0; i < 2 * n; i++){
		int a;
		cin >> a;
		Q.push(a);
	}
	int sum = 0;
	for(int i = 0; i < 2 * n; i++){
		int a = Q.top();
		Q.pop();
		if(i % 2 != 0)sum+=a;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  is <- map read . words <$> getLine :: IO [Int]
  let   a = head is
        b = is !! 1
        x = last is
  print $ (solve b x) - (solve (a-1) x)


solve :: Int -> Int -> Int
solve n x = if n < 0 then 0 else n `div` x+1


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

struct UnionFind {
    vector<int> par,rank,large;

    void init(int N){
        rank.assign(N,0);
        large.assign(N,1);
        par.resize(N);
        for(int i= 0; i < N; i++){
            par[i]=i;
        }
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx]<rank[ry]) {
            par[rx]=ry;
            large[ry]+=large[rx];
            large[rx]=0;
        }
        else {
            par[ry]=rx;
            large[rx]+=large[ry];
            large[ry]=0;
            if(rank[rx]==rank[ry])rank[x]++;
        }
    }

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

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

int main() {
  int N,K,L;
  cin>>N>>K>>L;
  UnionFind A,B,C;
  A.init(N);
  B.init(N);
  C.init(N);
  for(int i = 0; i < K; i++){
    ll x,y;
    cin>>x>>y;
    A.unite(x-1,y-1);
  }
  map<int,map<int,int>> m;
  for(int i = 0; i < L; i++){
    ll x,y;
    cin>>x>>y;
    B.unite(x-1,y-1);
  }
  for(int i = 0; i < N; i++) {
    m[B.root(i)][A.root(i)]++;
  }
  for(int i = 0; i < N; i++){
    cout<<m[B.root(i)][A.root(i)]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 33024
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef pair < long long , long long > pll;

const int N = 3e3+5;

const int mod = 1e9+7;

int n;
int ar[N];
bool vis[N][N][2];
pair < long long , long long > mem[N][N][2];


//turn 1 for jiro
pll go(int l , int r , int turn){
        if(l == r){
           if(turn & 1){
                return {0 , ar[l]};
           } else {
                return {ar[l] , 0};
           }
        }
        if(vis[l][r][turn])
            return mem[l][r][turn];
        pll best;
        pll c1 = go(l + 1 , r , 1 - turn);
        pll c2 = go(l , r - 1 , 1 - turn);
        if(turn & 1){
            if(c1.second + ar[l] > c2.second + ar[r])
                best = {c1.first , c1.second + ar[l]};
            else
                best = {c2.first , c2.second + ar[r]};
        } else {
            if(c1.first + ar[l] > c2.first + ar[r])
                best = {c1.first + ar[l] , c1.second};
            else
                best = {c2.first + ar[r] , c2.second};
        }
        vis[l][r][turn] = 1;
        return mem[l][r][turn] = best;
}


int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
    }
    memset(mem , -1 , sizeof mem);
    pll ret = go(1 , n , 0);
    printf("%lld\n" , ret.first-ret.second);
}


Measured memory_bytes: 300160
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int a,b,i,cnt=0,s=0,d=0,t=0;
    cin>>a>>b;
    for(i=a;i<=b;i++)
    {
    	t=i;
    	while(t>0)
    	{
    		d=t%10;
    		s=(s*10)+d;
    		t/=10;
		}
		if(s==i)
		cnt++;
		s=0;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int A,B;
	cin >> A >> B;

	if(A+B<10){
		cout << A+B << endl;
	}	
	else{
		cout <<"error"<<endl;
	}
}

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

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<pair<int, int>> ps(n);
	for (auto& p : ps) cin >> p.second >> p.first;
	sort(ps.begin(), ps.end());
	int now = 0, f = 1;
	for (auto p : ps)
	{
		now += p.second;
		f &= now <= p.first;
	}
	cout << (f ? "Yes" : "No") << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int X10=1024,X11=2048,X12=4096,X13=8196,X14=16392,X15=32786,X16=65536,X17=131072,X18=262144,X19=524288,X20=1048576;


void _ (){
    ll n,m,d;
    cin >> n >> m >> d;
    if(n == 2*d || d==0)cout << setprecision(14) <<(m-1)*1./n;
    else cout << setprecision(14) <<(m-1)*1.*(2*n-2*d)/n/n;

}


int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int allXOR = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        allXOR ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        if (i > 0)cout << " ";
        cout << (allXOR ^ a[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3976
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)
even.append((0,0))
odd.append((0,0))
youso = n//2
if even[0][0] == odd[0][0]: # 一緒だったら、差が小さい方を優先するのです?
    print(min(youso - even[1][1] + youso - odd[0][1],youso - odd[1][1] + youso - even[0][1]))
else: # 違うやつなら、それに合わせよう
    print(youso - even[0][1] + youso - odd[0][1])


Measured memory_bytes: 15460
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  int c[n];
  REP(i,n){
    cin>>c[i];
    c[i]--;
  }
  long long dp[n] = {};
  dp[0] = 1;
  int prev[200'000];
  fill(prev, prev+200'000, -1);
  REP(i,n){
    if(i==0){
      prev[c[i]] = i;
      continue;
    }
    if(prev[c[i]] == -1){
      dp[i] = dp[i-1];
    }else if(prev[c[i]] == i-1){
      dp[i] = dp[i-1];
    }else{
      dp[i] = dp[i-1] + dp[prev[c[i]]];
      dp[i] = mod(dp[i]);
    }
    prev[c[i]] = i;
  }
  long long ans = dp[n-1];
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 3328
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0

for i in range(N):
    for j in range(N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += (abs(X[i][k]-X[j][k]))**2
            if (tmp**0.5).is_integer():
                ans += 1
print(ans//2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

bool comp(pair< pair<string, int>, int> a, pair< pair<string, int>, int> b) {
  if (a.first.first != b.first.first){
    return a.first.first < b.first.first;
  }
  if (a.first.second != b.first.second){
    return a.first.second > b.first.second;
  }
}

int main() {

  int N;
  string s;
  int p_i;
  pair< pair<string, int>, int> p;
  vector< pair < pair<string, int> , int> > v;

  cin >> N;
  REP(i, 0, N) {
    cin >> s;
    cin >> p_i;
    p = make_pair(make_pair(s, p_i), i+1);
    v.push_back(p);
  }

  sort(v.begin(), v.end(), comp);

  REP(i, 0, N) {
    cout << v[i].second << endl;
  }


  return 0;
}


Measured memory_bytes: 256