akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

int main() {
    int n, p;
    string s;
    cin >> n >> p >> s;

    ll ans = 0;
    if (p == 2 || p == 5) {
        rep(i, n) {
            int x = s[i] - '0';
            if (x % p == 0) ans += i + 1;
        }
    } else {
        vector<int> pw(n);
        pw[0] = 1;
        for (int i = 1; i < n; ++i) pw[i] = (pw[i - 1] * 10) % p;

        vector<int> x(n + 1);
        for (int i = n - 1; i >= 0; --i) {
            x[i] = x[i + 1] + pw[n - 1 - i] * (s[i] - '0');
            x[i] %= p;
        }

        vector<ll> ct(p);
        for (int i : x) ++ct[i];

        for (ll i : ct) ans += i * (i - 1) / 2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2180
N = gets.to_i
works = Array.new
N.times do |i|
  works.push(gets.split(' ').map(&:to_i))
end
 
works = works.sort_by{|a| a[1]}
 
result = "Yes"
time = 0
N.times do |i|
  time += works[i][0]
  if time > works[i][1]
    result = "No"
    break
  end
end
 
puts result

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

int m, n;
int b[500], r[500];
int INF = (1<<30);

struct edge{int to, cap, rev;};

vector<edge> G[1100];
int level[1100];
int iter[1100];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int i=0; i<(int)G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i = iter[v]; i<(int)G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            int d=dfs(e.to, t, min(f, e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t]<0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while((f=dfs(s, t, INF)) > 0){
            flow += f;
        }
    }
}

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b, a%b);
}

int main(){
    while(true){
        cin>>m>>n;
        if(m==0) break;

        int s1=m+n, s2=s1+1, t=s2+1;
        memset(G, 0, sizeof(G));
        memset(level, 0, sizeof(level));
        memset(iter, 0, sizeof(iter));

        REP(i,m) cin>>b[i];
        REP(j,n) cin>>r[j];

        add_edge(s1, s2, m);
        REP(i,m) add_edge(s2, i, 1);
        REP(j,n) add_edge(m+j, t, 1);

        REP(i,m)REP(j,n){
            if(gcd(b[i], r[j])>1){
                add_edge(i, m+j, 1);
            }
        }

        int ans = max_flow(s1, t);
        cout<<ans<<endl;
    }
    return 0;
}


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

int main(void){
    string ans;
    cin >> ans;
    if(ans == "Sunny") cout << "Cloudy" << endl;
    if(ans == "Cloudy") cout << "Rainy" << endl;
    if(ans == "Rainy") cout << "Sunny" << endl;

    return 0;
}

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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }
    else{
        cout << (a + b) / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
s=list(input())
n=len(s)
l=[]
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    l.append(i)
ans=[0]*len(s)
for i in l:
  cntR,cntL=1,1
  j,k=i,i+1
  while j>0:
    if s[j]==s[j-1]:
      j-=1
      cntL+=1
    else:
      break
  while k<n-1:
    if s[k]==s[k+1]:
      k+=1
      cntR+=1
    else:
      break
  ans[i+1],ans[i]=(cntR+1)//2+cntL//2,cntR//2+(cntL+1)//2
print(*ans)

Measured memory_bytes: 8992
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<iomanip>
#include<list>
using namespace std;

class Obj {
public:
	int price;
	int weight;
	char type;
	unsigned long long date;
	string name;
};

bool PriceSort(const Obj& a, const Obj& b);
bool WeightSort(const Obj& a, const Obj& b);
bool TypeSort(const Obj& a, const Obj& b);
bool DateSort(const Obj& a, const Obj& b);
bool NameSort(const Obj& a, const Obj& b);

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

	vector<Obj> goods(n);

	for (int i = 0; i < n; i++) {
		cin >> goods[i].price >> goods[i].weight >> goods[i].type >> goods[i].date >> goods[i].name;
	}

	sort(goods.begin(), goods.end(), PriceSort);

	for (int i = 0; i < goods.size(); i++) {
		cout << goods[i].price << " " << goods[i].weight << " " << goods[i].type << " " << goods[i].date << " " << goods[i].name;
		cout << endl;
	}

	return 0;
}

bool PriceSort(const Obj& a, const Obj& b) {
	if (a.price == b.price) {
		return WeightSort(a,b);
	}

	return a.price < b.price;
}

bool WeightSort(const Obj& a, const Obj& b) {
	if (a.weight == b.weight) {
		return TypeSort(a, b);
	}

	return a.weight < b.weight;
}

bool TypeSort(const Obj& a, const Obj& b) {
	if (a.type == b.type) {
		return DateSort(a, b);
	}

	return a.type < b.type;
}

bool DateSort(const Obj& a, const Obj& b) {
	if (a.date == b.date) {
		return NameSort(a, b);
	}

	return a.date < b.date;
}

bool NameSort(const Obj& a, const Obj& b) {

	for (int i = 0; i < a.name.size() && i < b.name.size(); i++) {
		if (a.name[i] != b.name[i]) {
			return a.name[i] < b.name[i];
		}
	}

	return a.name.size() < b.name.size();

}


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

using namespace std;

using ll = long long;
using ld =long double;

using vl = vector<ll>;
using vvl = vector<vl>;

using pll = pair<ll,ll>;

ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define xx first
#define yy second

#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define FORD(i,a,b) for(ll i = (b)-1; i >= a; i--)

#define DBG(X) ({ if(0) cerr << "DBG: " << (#X) << " = " << (X) << endl; })

int main(){
	ios_base::sync_with_stdio(false);


	ll A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	ll maw = A * 100;
	ll maz = 0;

	FOR(a, 0, 40){
		FOR(b, 0, 40){
			if(a == 0 && b == 0) continue;
			ll wat = (a * A + b * B) * 100;
			ll zuk = (a * A + b * B) * E;
			if(wat > F) continue;
			DBG(wat);
			DBG(zuk);

			zuk = min(zuk, F - wat);

			FOR(c, 0, 10001){
				ll czu = c * C;
				ll re = zuk - czu;
				if(re < 0) continue;

				ll d = re / D;

				ll zu = (d * D + czu);

				if(wat + zu <= F){
					DBG(wat);
					DBG(zu);
					if((maz * (wat + zu)) < zu * (maw + maz)){
						maz = zu;
						maw = wat;
						/*
						DBG(maz);
						DBG(maw);
						*/
					}
				}
			}

			FOR(d, 0, 10001){
				ll czu = d * D;
				ll re = zuk - czu;
				if(re < 0) continue;

				ll c = re / C;

				ll zu = (c * C + czu);

				if(wat + zu <= F){
					DBG(wat);
					DBG(zu);
					if((maz * (wat + zu)) < zu * (maw + maz)){
						maz = zu;
						maw = wat;
						/*
						DBG(maz);
						DBG(maw);
						*/
					}
				}
			}
		}
	}

	cout << maw + maz << " " << maz << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int selectionSort(int *ori,int );

int main()
{
  int i,atai,n,ori[100];
  
  scanf("%d",&n);
  if(n<1 || n>100) exit(7);
  for(i=0;i<n;i++){
    scanf("%d",&ori[i]);
  }

  atai=selectionSort(ori,n);

   for(i=0;i<n;i++){
     printf("%d",ori[i]);
     if(i<n-1) printf(" ");
   }
   
   printf("\n");
   
   printf("%d\n",atai);
  
  return 0;
}

int selectionSort(int *ori,int n)
{
  int i,j,count=0,minj,kawari,space,record;

  for(i=0;i<n;i++){
    space=i;
    for(j=i;j<n;j++){
      if(ori[j]<ori[space]){
	space=j;
	record=ori[j];
      }
    }
    if(space!=i){ 
    kawari=ori[i];
     ori[i]=record;
      ori[space]=kawari;
      count++;
    }
  }

  return count;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int n,v[1002];
int now;
double r=0;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	sort(v+1,v+n+1);
	now=v[1];
	for(int i=2;i<=n;i++){
		if((now+v[i])%2){
			r+=1;
		}
		now=(now+v[i])/2;
		r/=2;
		if(r>=1){
			r--;
			now++;
		}
	}
	printf("%.12f",now+r);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    rep(i,N)cin >> W[i];
    vector<int> sum(N+1);
    for(int i=0;i<N;i++){
        sum[i+1]+=sum[i]+W[i];
    }
    int res = 1e9;
    for(int i=0;i<N;i++){
        res = min(res,abs((sum[N]-sum[i])-sum[i]));
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    int score=0;
    rep(i, n-1)
    {
        if (s[i]==s[i+1]) ++score;
    }
    
    int ans = min (score + 2 * k, n - 1);
    
    cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 512
N=int(input())
W=[]
for i in range(N):
    A,B=map(int,input().split())
    W.append((A+B,A,B))
W.sort(key= lambda x:x[0],reverse=True)

isTakahashiTurn=True
score=0
for i in range(N):
    if isTakahashiTurn:
        score+=W[i][1]
        isTakahashiTurn=False
    else:
        score-=W[i][2]
        isTakahashiTurn=True
print(score)



Measured memory_bytes: 22128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
const int mod=(int)1e9+7;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n; set<int>s;
    while(n--){
        int i;
        cin>>i;
        if(s.find(i)==s.end()){
            s.insert(i);
        }
        else s.erase(i);
    }
    cout<<s.size();
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    int r = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] > i + 1) r = -1;
    }

    if (r < 0) {
        cout << -1 << endl;
    } else {
        vector<int> r(n);
        for (int i = n - 1; i >= 0; i--) {
            for (int j = i; j >= 0; j--) {
                if (b[j] == j + 1) {
                    r[i] = b[j];
                    b.erase(b.begin() + j);
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            cout << r[i] << endl;
        }
    }

    //先頭は必ず1になる
    //12345より小さければ作れる 大きければ作れない
    //1 1 1 2 2 1 2 3 2
    //0 1 2 2 3 5 5 5 7
    //9 8 7 7 6 4 4 4 2
    //7回押される必要があるということは、9回のうち2回目以前に挿入される必要がある
    //1 1 1 2 2 1 2 3 8
    //1 1 1 2 2 1 2 3 8
    //右にある自分より大きい数

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>

typedef long long ll;

using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 1e12;

int main(){
  ll i,j,k,n,m;
  string s;
  cin >> s;
  bool flag = false;
  for (i = 0; i < 3; i++)
  {
      if(s[i]==s[i+1])
          flag = true;
  }
  if(!flag)
      cout << "Good" << endl;
    else
    cout << "Bad" << endl;
    return 0;
}


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

table = [[0]*10 for i in range(10)]

for i in range(1, N+1):
  s = str(i)
  id1 = int(s[0])
  id2 = int(s[-1])
  table[id1][id2] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += table[i][j]*table[j][i]

print(ans)

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
  vector<vector<long long>> lis(N+1);
  vector<long long> path(N+1, LLONG_MAX);
  for(long long i = 0; i < M; i++){
    lis[A[i]].push_back(B[i]);
    lis[B[i]].push_back(A[i]);
  }

  queue<long long> q;
  q.push(1);
  path[0] = 0;
  path[1] = 0;

  while(!q.empty()){
    long long edge = q.front();
    //cout << edge << ": ";
    for(auto i: lis[edge]){
      //cout << i << " ";
      if(path[i] == LLONG_MAX) {
        path[i] = edge;
        q.push(i);
      }
    }
    //cout << endl;
    q.pop();
  }

  if(find(path.begin(), path.end(), LLONG_MAX) == path.end()) {
    cout << YES << endl;
    for(long long i = 2; i <= N; i++){
       cout << path[i] << endl;
    }
  }
  else {
    cout << NO << endl;
  }

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&A[i]);
    scanf("%lld",&B[i]);
  }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 15932
#include <iostream>

int main() {
    int N, M, X;
    std::cin >> N >> M >> X;

    int A;
    int count_left = 0;
    int count_right = 0;
    for (int i = 0; i < M; i++) {
        std::cin >> A;

        if (A < X) {
            count_left++;
        } else {
            count_right++;
        }
    }

    if (count_left < count_right) {
        std::cout << count_left << std::endl;
    } else {
        std::cout << count_right << std::endl;
    }

    return 0;
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll n,q;
vector<ll> ar(500005);
vector<pair<pll,ll>> queries(500005);
ll bit[500005]={0};
vector<ll> last(500005,-1);

ll query(ll r)
{
    ll ans=0;

    for(;r>=0;r=(r&(r+1))-1)
    ans+=bit[r];

    return ans;
}

void update(ll idx,ll delta)
{
    for(;idx<n;idx|=(idx+1))
    bit[idx]+=delta;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        cin>>n>>q;
        
        // ar.resize(n);
        // queries.resize(q);

        for(ll i=0;i<n;i++)
        {
            ll x;
            cin>>x;
            x--;
            ar[i]=x;
        }

        for(ll i=0;i<q;i++)
        {
            ll x,y;
            cin>>x>>y;

            x--,y--;

            queries[i].ff.ss=x;
            queries[i].ff.ff=y;
            queries[i].ss=i;

        }

        sort(queries.begin(),queries.begin()+q);

        ll qcount=0;

        vector<ll> ans(q,0);

        for(ll i=0;i<n;i++)
        {
            if(last[ar[i]]!=-1)
            update(last[ar[i]],-1);

            update(i,1);
            last[ar[i]]=i;

            while(qcount<q && queries[qcount].ff.ff==i)
            {
                ans[queries[qcount].ss]=query(queries[qcount].ff.ff)-query(queries[qcount].ff.ss-1);
                qcount++;
            }
        }

        for(ll i=0;i<q;i++)
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 31164
#include <iostream>
#include<string.h>
using namespace std;

int main(){
  int r = 0,c = 0;
  int matrix[101][101] = {{0}};

  cin >> r >> c;
  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      cin >> matrix[i][j];
      matrix[i][c] +=  matrix[i][j];
      matrix[r][j] +=  matrix[i][j];
      matrix[r][c] +=  matrix[i][j];
    }
  }
  for(int i = 0; i <= r; i++){
    for(int j = 0; j <= c; j++){
      cout << matrix[i][j];
      if(c != j){
        cout << " ";
      }
    }
    cout << endl;
  }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    for (int i = 0; i < N; ++i)
        cin >> S[i];
    for (int i = 0; i < M; ++i)
        cin >> T[i];

    vector<vector<ll>> dp(N + 2, vector<ll>(M + 2));
    dp[0][0] = 1;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
            if (i > 0)
                dp[i][j] += dp[i - 1][j];
            if (j > 0)
                dp[i][j] += dp[i][j - 1];
            if (i > 0 && j > 0 && S[i - 1] != T[j - 1])
                dp[i][j] -= dp[i - 1][j - 1];
            dp[i][j] %= MOD;
        }
    }
    if (dp[N][M] < 0)
        dp[N][M] += MOD;
    cout << dp[N][M] << endl;

    return 0;
}


Measured memory_bytes: 31744
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    int N;
    cin >> N;
    cout << N*N*N << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	int a,b;
    cin>>a>>b;
    cout<<(a*b);
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 3668
#pragma GCC optimize(2)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
#include <sstream>
#include <ctime>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mes(a, b) memset((a), (b), sizeof (a))
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;

struct Point{
    double x, y;
    Point(double a = 0, double b = 0) : x(a), y(b) {};
};

typedef Point Vector;
inline Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
inline Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}
inline Vector operator * (Vector A, double x) {return Vector(A.x * x, A.y * x);}
inline Vector operator / (Vector A, double x) {return Vector(A.x / x, A.y / x);}
inline double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //向量点乘
inline double Len(Vector A) {return sqrt(Dot(A, A));}
inline double Ang(Vector A, Vector B) {return acos(Dot(A, B) / Len(A) / Len(B));} //向量夹角
inline double Cro(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //向量叉乘
inline double Area(Vector A, Vector B) {return Cro(A, B) * 0.5;} //组成三角形面积
inline Vector Rotate(Vector A, double rad) {return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));} //向量逆时针旋转角度rad
inline Vector Normal(Vector A) {double len = Len(A); return Vector(-A.y / len, A.x / len);}//求向量A的单位法线

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 0x3f3f3f3f;
const int inf = 0x7fffffff;
const int mod = 9901;
const double PI = acos(-1);

inline void Solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for ( int i = 0; i < n; i ++ ) cin >> a[i];
    sort(all(a));

    ll ans = a[n - 1];
    int num = 2;
    for ( int i = n - 2; i + 1; i -- ) {
        if ( num < n ) ans += a[i], num ++;
        else break;
        if ( num < n ) ans += a[i], num ++;
      	else break;
    }

    cout << ans << endl;
}

int main() {
    IosF;
    Solve();
    return 0;
}


Measured memory_bytes: 4464
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int x;
    R(x);
    W(x*x*x/27.);
    return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int N;
    cin >> N;
    int ans = INF;
    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n,d;
	cin >> n >> d;
	cout << (n-1)/(2*d+1)+1 << endl;
	return 0;
}

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


int main() {
  int N;
  cin >>N;
  
  vector<char> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int M =0;
  for (int i = 0; i < N; i++) {
    if(vec.at(i)=='R'){
      M ++;
    }
    else{
      M +=0;
    }
  }
  
  int P =0;
  for (int i = 0; i < M; i++) {
    if(vec.at(i)=='W'){
      P ++;
    }
    else{
      P +=0;
    }
  }
  
  cout << P <<endl;

}


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

using ll = long long;
using Pi = pair < int, int >;

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template < typename T > T gcd(T a, T b) { return ( b ? gcd(b, a % b) : a ); }
template < typename T > T lcm(T a, T b) { return ( a / gcd(a, b) * b ); }

int main()
{
    ll T1, T2;
    ll A1, A2;
    ll B1, B2;
    
    ll A, B;

    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    
    A = T1 * (B1 - A1);
    B = T2 * (B2 - A2);

    if ( A < 0 ) A = -A, B = -B;
    if ( A + B == 0 ) { cout << "infinity" << endl; return ( 0 ); } //これはずっと会う
    if ( A + B > 0 ) { cout << 0 << endl; return ( 0 ); } //速さが圧倒的
    
    //A + B < 0
    ll sa = -B - A;
    cout << (A / sa) * 2 + (A % sa > 0 ? 1 : 0) << endl;

    return ( 0 );
}


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


int main() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i,t) cin >> a[i];
  sort(rng(a));
  int n = 2 * a[t-1] - k -1;
  if(n<0) cout << 0 << endl;
  else cout << n << endl;
  return 0;
}

Measured memory_bytes: 3604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int k(int j,vector<vector<char>>&c,vector<vector<int>>&cs,int x,int y){
    if(cs[x][y]>=0) return cs[x][y];
    if(x==0||y==0) return cs[x][y]=0;
    return cs[x][y]=k(j,c,cs,x-1,y-1)+(c[x-1][j]==c[y-1][j+1]);
}

int rec(int j,vector<vector<char>>&c,vector<vector<int>>&dp,vector<vector<int>>&cs,int x,int y){
    if(dp[x][y]>=0) return dp[x][y];
    if(x==0||y==0) return dp[x][y]=0;
    return dp[x][y]=min(rec(j,c,dp,cs,x-1,y),rec(j,c,dp,cs,x,y-1))+k(j,c,cs,x,y);
}

class DFriction {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int h,w;
        in>>h>>w;
        vector<vector<char>> c(h,vector<char>(w));
        for(auto&s:c) for(auto&t:s) in>>t;
        ll ans=0;
        fr(j,w-1){
            vector<vector<int>> dp(h+1,vector<int>(h+1,-1)),cs(h+1,vector<int>(h+1,-1));
            ans+=rec(j,c,dp,cs,h,h);
        }
        out<<ans<<endl;
    }
};

int main() {
    DFriction solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    int n,w;
    cin>>n>>w;

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

    int dp[n+1][w+1];

    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0 || j==0)dp[i][j]=0;

            else if(a[i-1]>j)dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(b[i-1]+dp[i-1][j-a[i-1]],dp[i-1][j]);
        }
    }

    cout<<dp[n][w];
}

Measured memory_bytes: 79104
A,B=list(map(int, input().split()))
if A==B:
  print(A)
  exit()
a=A//4
b=B//4

def xorsum(L):
  if len(L)==1:
    return L[0]
  a=L[0]
  for i in range(1,len(L)):
    a^=L[i]
  return a

if a==b:
  L=[A+i for i in range(B-A+1)]
  print(xorsum(L))
  exit()
c=[a*4+i for i in range(4) if i>=A%4]
d=[b*4+i for i in range(4) if i<=B%4]
print(xorsum(c)^xorsum(d))

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(0);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;

const int MOD = inf + 7;

signed main(){
	fast;
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	int a[3][3];
	f(i,0,3)	f(j,0,3)	cin >> a[i][j];

	map<int,int> m;
	int n;
	cin >> n;
	f(i,0,n)
	{
		int x;
		cin >> x;
		m[x] = 1;
	}

	f(i,0,3)	f(j,0,3)	a[i][j] = m[a[i][j]];

	int ok = 0;
	if(a[0][0] && a[0][1] && a[0][2]) ok = 1;
	if(a[1][0] && a[1][1] && a[1][2]) ok = 1;
	if(a[2][0] && a[2][1] && a[2][2]) ok = 1;

	if(a[0][0] && a[1][0] && a[2][0]) ok = 1;
	if(a[0][1] && a[1][1] && a[2][1]) ok = 1;
	if(a[0][2] && a[1][2] && a[2][2]) ok = 1;

	if(a[0][0] && a[1][1] && a[2][2]) ok = 1;
	if(a[2][0] && a[1][1] && a[0][2]) ok = 1;

	cout << (ok ? "Yes" : "No");

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll x, n;
  cin >> x >> n;
  vector<ll> p(130, 0);
  rep(i, n) {
    ll temp;
    cin >> temp;
    p[temp] = INF;
  }
  repz(i, 0, SIZE(p)) {
    if (p[i] == 0) {
      p[i] = abs(i - x);
    }
  }
  ll res = INF;
  repz(i, 0, SIZE(p)) {
    if (p[i] == INF) continue;
    chmin(res, p[i]);
  }
  repz(i, 0, SIZE(p)) {
    if (p[i] == res) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int p[200005], s[200005], a[200005];

int main()
{
	IO_OP;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++)
		p[i] = max(p[i-1], a[i]);
	for(int i=n;i>=1;i--)
		s[i] = max(s[i+1], a[i]);
	for(int i=1;i<=n;i++) {
		cout << max(p[i-1], s[i+1]) << endl;
	}
	
}



Measured memory_bytes: 3968
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

n,x=map(int, input().split())
l=list(map(int, input().split()))

bound = 1
pos = 0

for i in range(n):
    pos += l[i]
    if pos > x:
        break
    bound += 1

print(bound)

Measured memory_bytes: 12424
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long n; long k;
  cin >> n;
  cin >> k;
  long ans;
  // k = 0?
  if (k == 0){
    ans = n *n;
  }else{
    for (size_t b = k+1; b <= n; b++) {
      ans += n/b * (b - k);
      if(n % b >= k){
        ans += n%b - k + 1;
      }
    }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
def slove(a, b, s):
    if s[a] != "-":
        return "No"
    for i in range(a + b + 1):
        if i == a:
            pass
        else:
            if s[i].isdigit() == False:
                return "No"
    return "Yes"

if __name__ == "__main__":
    ab = input().split()
    a = int(ab[0])
    b = int(ab[1])
    s = list(input())

    print(slove(a, b, s))

Measured memory_bytes: 3060
package main

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

const (
	yes = "Yes"
	no  = "No"
)

var sc = bufio.NewScanner(os.Stdin)

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

func isEasy(i int, r rune) bool {
	return (i%2 == 0 && (r == 'L' || r == 'U' || r == 'D')) ||
		(i%2 == 1 && (r == 'R' || r == 'U' || r == 'D'))
}

// IsEasy ...
func IsEasy(in string) string {
	for i, v := range in {
		if !isEasy(i+1, v) {
			return no
		}
	}
	return yes
}

func main() {
	s := nextString()
	fmt.Println(IsEasy(s))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

void solve(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;

}

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <bitset>
#define ll long long 
#define ri register int 
using std::min;
using std::bitset;
using std::max;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=405;
const int inf=0x7fffffff;
bitset <maxn> o[maxn];
bool ok[maxn];
int a[100005],b[100005],m,n;
int main(){
    int x,y;
    read(n),read(m);
    for(ri i=1;i<=m;i++)read(a[i]),read(b[i]);
    for(ri i=1;i<=n;i++){
        o[i][i]=1;
        for(ri j=m;j>=1;j--){
            x=o[i][a[j]],y=o[i][b[j]];
            if(x&y){
                ok[i]=1;
                continue;
            }
            if(x){o[i][b[j]]=1;}
            if(y){o[i][a[j]]=1;}
        }
    }
    ll ans=0;
    for(ri i=1;i<=n;i++){
        if(ok[i])continue;
        for(ri j=i+1;j<=n;j++){
            if(ok[j])continue;
            if(!((o[i]&o[j]).any()))ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  int i=0,N=IN(),r=0,w=0;char *stones=(char*)malloc(sizeof(char)*(N+1));stones[N]=0;
  if(stones==NULL||!scanf("%s",stones)){exit(EXIT_FAILURE);}
  while(N--){if(stones[N]=='R')r++;}while(r--){if(stones[i++]=='W')w++;}
  printf("%d\n",w);return free(stones),0;
}

Measured memory_bytes: 1748
import sys
from itertools import accumulate
from bisect import bisect_right

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A_ = [0] + list(accumulate(A))
    B_ = [0] + list(accumulate(B))

    init = bisect_right(A_, k)
    res = init - 1
    for i in range(init):
        t = k - A_[init - i - 1]
        idx = bisect_right(B_, t)
        res = max(res, init - i - 1 + idx - 1)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 50564
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=401;
const int M=1e5+10;
int x[M],y[M];
int n,m;
bitset<N>del[N];
bool cant[N];
int main()
{
	init(n),init(m);int u,v;
	for(int i=1;i<=m;++i) {
		init(u),init(v);
		if(u>v) swap(u,v);
		x[i]=u,y[i]=v;
	}
	for(int u=1;u<=n;++u) {
		del[u].set(u);
		for(int i=m;i;--i) {
			int a=x[i],b=y[i];
			if(del[u][a]&&del[u][b]) {cant[u]=1;break;}
			if(del[u][a]) del[u].set(b);
			if(del[u][b]) del[u].set(a);
		}
	}int ans=0;
	for(int i=1;i<=n;++i) {
		if(cant[i]) continue;
		for(int j=i+1;j<=n;++j){
			if(cant[j]) continue;
			if(!(del[i]&del[j]).any()) ++ans;
		}
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

X = I()

for a in range(500):
    for b in range(500):
        if a**5-b**5 == X:
            print(a,b)
            exit()
        if a**5-(-b)**5 == X:
            print(a,-b)
            exit()
        if (-a)**5-(-b)**5 == X:
            print(-a,-b)
            exit()

Measured memory_bytes: 68116
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    ll n, c;
    cin >> n >> c;
    V<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    V<V<ll>> sum(c + 1, V<ll>(401));
    sum[0].assign(401, 1);
    rep(i, c) rep(j, 401) sum[i + 1][j] = sum[i][j] * j % mod;
    rep(i, c + 1) rep(j, 400)(sum[i][j + 1] += sum[i][j]) %= mod;
    V<V<ll>> dp(2, V<ll>(c + 1));
    dp[0][0] = 1;
    rep(i, n) rep(j, c + 1) {
        dp[i + 1 & 1][j] = 0;
        rep(k, j + 1) {
            (dp[i + 1 & 1][j] +=
             dp[i & 1][j - k] *
             ((sum[k][b[i]] - sum[k][a[i] - 1] + mod) % mod) % mod) %= mod;
        }
    }
    cout << dp[n & 1][c] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <cstdio>

typedef long long ll;

ll pow_26[15];

void encode(ll n, int p)
{
    if(p == 1)
    {
        putchar('a' + n - 1);
        return;
    }

    putchar('a' + (n - 1) / pow_26[p - 1]);
    encode((n - 1) % pow_26[p - 1] + 1, p - 1);
}

int main()
{
    ll n; scanf("%lld", &n);
    pow_26[0] = 1;
    for(int i = 1; i < 13; i++) pow_26[i] = pow_26[i - 1] * 26LL;
    int p = 0;
    while(pow_26[p + 2] - 26LL < n * 25LL) p++;
    ll x = n - (pow_26[p + 1] - 26LL) / 25LL;
    encode(x, p + 1);
    return 0;
}

Measured memory_bytes: 1640
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	string a, b;
	cin >> a >> b;
	string s = a + b;
	ll num = stoi(s, nullptr, 10);
	ll temp = (int)sqrt(num);
	if (num == temp * temp){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  vector<string> ans[10];
  ans[0].push_back("a");
  for (ll i = 1; i < 10; i++) {
    for (const auto& x : ans[i - 1]) {
      ll count = 0;
      char chars[] = {
          'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
      };
      for (const auto& c : chars) {
        if (x.find(c) != string::npos) {
          count++;
        }
      }
      for (ll j = 0; j < count + 1; j++) {
        ans[i].push_back(x + (char)('a' + j));
      }
    }
  }
  for (const auto& y : ans[N - 1]) {
    cout << y << endl;
  }

  return 0;
}


Measured memory_bytes: 9588
import java.util.Scanner;

class Content{
    private String str;

    private static char bracketComp(char in){
        if (in == '(') return ')';
        return ']';
    }

    public Content(String s){
        str = s;
    }

    public boolean balanced(){
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++){
            if (array[i] == '(' || array[i] == '['){
                String tmp = "";
                Boolean bal = false;
                int skip = 0;
                for (int j = i + 1; j < array.length; j++){
                    if (array[j] == bracketComp(array[i]) && skip-- == 0){
                        bal = true;
                        i = j;
                        break;
                    }
                    else if (array[j] == array[i]) skip++;
                    tmp += array[j];
                }
                if (!bal) return false;
                Content inContent = new Content(tmp);
                if (!inContent.balanced()) return false;
            }
            else if (array[i] == ')' || array[i] == ']') return false;
        }
        return true;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true){
            String line = sc.nextLine();
            if (line.equals(".")) break;
            Content cont = new Content(line);
            if (cont.balanced()) System.out.println("yes");
            else System.out.println("no");
        }
    }
}

Measured memory_bytes: 62844
#include "omp.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>	
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <random>
#include <bitset>
#include <unordered_set>
#include <cassert>
#include <list>


using namespace std;

typedef long long ll;
typedef long double ld;

const int sze = 4e3 + 10;

int dp[sze][sze];
int t[sze];
vector<int> b, w;


void add(int ind, int v)
{
	for (int i = ind; i < sze; i += i&-i)
		t[i] += v;
}


int get(int ind)
{
	if (!ind)
		return 0;

	int cnt = 0;
	for (int i = ind; i; i -= i &-i)
		cnt += t[i];

	return cnt;
}


int get(int l, int r)
{
	return get(r) - get(l - 1);
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;
	
	b.resize(n + 1), w.resize(n + 1);
	for (int i = 1; i <= 2 * n; ++i)
	{
		int v;
		char c;
		cin >> c >> v;

		if (c == 'B')
			b[v] = i;
		else
			w[v] = i;
	}


	dp[0][0] = 0;

	for (int i = 1; i <= n; ++i)
	{
		dp[i][0] = dp[i - 1][0] + get(w[i], 2 * n);
		add(w[i], 1);
	}

	fill(t, t + sze, 0);

	for (int i = 1; i <= n; ++i)
	{
		dp[0][i] = dp[0][i - 1] + get(b[i], 2 * n);
		add(b[i], 1);
	}

	for (int i = 1; i <= n; ++i)
	{
		fill(t, t + sze, 0);//2 * n

		for (int z = 1; z < i; ++z)
			add(w[z], 1);

		for (int j = 1; j <= n; ++j)
		{
			int W = get(w[i], 2 * n) + int(b[j] > w[i]);
			int B = get(b[j], 2 * n) + int(w[i] > b[j]);

			dp[i][j] = min(dp[i - 1][j] + W, dp[i][j - 1] + B);
			add(b[j], 1);
		}
	}

	cout << dp[n][n];

	return 0;
}

Measured memory_bytes: 32512