akhauriyash/Code-Regression huggingface dataset:
<?php
$n = intval(trim(fgets(STDIN)));
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
$sum = 0;
$mod = 10**9+7;
for($i = 0; $i < 60; $i++){
  $c = 0;
  foreach($a as $b){
    $c += ($b >> $i) & 1; 
  }
  $d = $c * ($n-$c) % $mod;
  $d *= (1<<$i) % $mod;
  $sum += $d % $mod;
  $sum %= $mod;
}
echo $sum;


Measured memory_bytes: 40936
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void swap(int *x,int *y){int tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
//next_permutation
//from https://qiita.com/Nikkely/items/0ddca51b3c0e60afbaab
int next_permutation(int *a,int n){
    int x=-1,y=-1;
    for(int i=n-2;i>=0;i--)if(a[i]<a[i+1]){x=i;break;}
    for(int i=n-1;x!=-1&&i>=0;i--)if(a[x]<a[i]){y=i;break;}
    if(x==-1||y==-1)return 1;
    swap(&a[x],&a[y]);
    qsort(&a[x+1],n-(x+1),sizeof(int),asc_cmp);
    return 0;
}

int main(){
    int n;scanf("%d",&n);
    int p[20];for(int i=0;i<n;i++)scanf("%d",&p[i]);
    int q[20];for(int i=0;i<n;i++)scanf("%d",&q[i]);

    char p_str[20],q_str[20];
    for(int i=0;i<n;i++)p_str[i]=p[i]+'0';
    for(int i=0;i<n;i++)q_str[i]=q[i]+'0';
    p_str[n]=q_str[n]='\0';

    int a[n];for(int i=1;i<=n;i++)a[i-1]=i;

    int index[2];
    static char list[100000][20];
    for(int i=0;1;i++){
        for(int j=0;j<n;j++)list[i][j]='0'+a[j];
        list[i][n]='\0';
        if(!strcmp(list[i],p_str))index[0]=i;
        if(!strcmp(list[i],q_str))index[1]=i;
        if(next_permutation(a,n))break;
    }
    
    printf("%d\n",abs(index[0]-index[1]));
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

int main() {
  int n, k;

  cin >> n >> k;

  bool flag[1000] = {};

  int count = 0;
  for (int i = 0; i < k; i++){
    int d;

    cin >> d;

    for (int j = 0; j < d;j++) {
      int c;
      cin >> c;
      if(flag[c] == false) {
        flag[c] = true;
        count++;
      }
    }
  }

  cout << n - count << endl;
}

Measured memory_bytes: 3636
N = int(input())
a = list(map(int, input().split()))

d = [0] * 9
for i in a:
    if i <= 399:
        d[0] = 1
    elif i <= 799:
        d[1] = 1
    elif i <= 1199:
        d[2] = 1
    elif i <= 1599:
        d[3] = 1
    elif i <= 1999:
        d[4] = 1
    elif i <= 2399:
        d[5] = 1
    elif i <= 2799:
        d[6] = 1
    elif i <= 3199:
        d[7] = 1
    else:
        d[8] += 1

minimam = max(1, sum(d[:8]))
maximam = sum(d)

print(minimam, maximam)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define F(i,n) for(int i=0;i<n;i++)
#define VE(i,v) for(int i = 0;i < (v).size();i++)
using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 
ll helper(vvl &arr, vvl &dp, int i, int choice)
{
	int sz = arr[0].size();
	if (i==sz)
		return 0;
	if(dp[choice][i]==-1LL)
	{
		for(int k =0; k<3; k++)
		{
			if(k!=choice)
				dp[choice][i] = max(dp[choice][i], arr[k][i] + helper(arr, dp, i+1, k));
		}
		//cout<<i<<" "<<choice<<" "<<dp[choice][i]<<"\n";
	}
	return dp[choice][i];
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	
	
	

	for(int tc = 0; tc < T; tc++)
	{
		int N;
		cin>> N;
		vvl arr(3, vl(N));
		vvl dp(3, vl(N,-1LL));
		for(int i=0; i < N; i++)
			for(int j=0; j<3; j++)
				cin>>arr[j][i];
		ll ans = 0;
		for(int i=0; i <3; i++)
			ans = max(ans, arr[i][0] + helper(arr, dp, 1, i));

		
		cout<<ans<<"\n";
	}

 
 
 
	return 0;
}
 
 


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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K; cin >> N >> K;
    vector<int> H(N); rep(i, N) cin >> H[i];
    sort(H.begin(), H.end());
    ll ans = 0;

    for (int i = 0; i < (int)H.size() - K; i++) {
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  int N, M;
  cin >> N >> M;
  string c, d;
  char a[N][N];
  char b[M][M];
  
  rep(i, N){
    cin >> c;
    rep(j, N){
      a[i][j] = c[j];
    }
  }

  rep(i, M){
    cin >> d;
    rep(j, M){
      b[i][j] = d[j];
    }
  }

  // 含むかどうかみていく
  bool flag = false;
  rep(i, N-M+1){
    rep(j, N-M+1){
      if(a[i][j] == b[0][0]){
        flag = true;
        for(int k = 0; k < M; k++){
          for(int l = 0; l < M; l++){
            if(a[k+i][l+j] != b[k][l]) {
              flag = false;
              break;
            }
          }
        }
        if(flag){
          print("Yes");
          return 0;
        }
      }
    }
  }
  
  print("No");

}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]
ans = 10 ** 9
if all(A[i] % 2 == 0 for i in range(n)):
    for i in range(n):
        count = 0
        while A[i] % 2 == 0:
            A[i] //= 2
            count += 1
        ans = min(ans, count)
else:
    ans = 0
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int H, W, M;
    cin >> H >> W >> M;
    vector<int> R(H), C(W);
    
    set<pint> st;
    REP(i, M) {
        int h, w;
        cin >> h >> w;
        h--; w--;
        st.emplace(h, w);
        R[h]++; C[w]++;
    }

    int ret = 0;
    int mh = *max_element(ALL(R)), mw = *max_element(ALL(C));
    vector<int> GH, GW;
    REP(i, H) if (R[i] == mh) GH.emplace_back(i);
    REP(i, W) if (C[i] == mw) GW.emplace_back(i);

    if (ll(GH.size())*GW.size() > M) {
        cout << mh + mw << endl;
        return 0;
    }
    for(auto h : GH) for (auto w : GW) {
        if (!st.count(pint(h, w))) {
            cout << mh+mw << endl;
            return 0;
        }
    }
    
    cout << mh+mw-1 << endl;
    

    return 0;
}

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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;
constexpr double PI=3.14159265358979323846;

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

    int tmp;
    fr(i,0,5){
        cin >> tmp;
        if(tmp==0) cout << i+1 << "\n";
    }
}   

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

int main()
{
    int n,m;
    cin>>n>>m;
    while(n!=0)
    {
        if(n<m)swap(n,m);
        n%=m;
    }
    cout<<m<<endl;
}



Measured memory_bytes: 3088
input = readlines
index = input[0].chomp.to_i
cards = input[1].split(' ').map(&:to_i)
A,B = [],[]
i = 1

while i <= index
  if(i.odd?)
    A.push(cards.max)
  else
    B.push(cards.max)
  end
  ai = cards.index(cards.max)
   cards.delete_at(ai)
   i += 1
end

p A.sum - B.sum 

Measured memory_bytes: 14344
package main

import (
    "fmt"
    "math"
)

var n int
var dp [][]int64

func main() {
  fmt.Scanf("%d", &n)
  var a []int64
  a = make([]int64, n)
  for i := 0; i < n; i++ {
    fmt.Scanf("%d", &a[i])
  }
  dp = make([][]int64, n + 1)
  for i := 0; i < n + 1; i++ {
    dp[i] = make([]int64, 2)
    dp[i][0] = -99999999
    dp[i][1] = -99999999
  }
  dp[0][0] = 0
  for i := 0; i < n; i++ {
    dp[i + 1][0] = int64(math.Max(float64(dp[i][0] + a[i]), float64(dp[i][1] - a[i])))
    dp[i + 1][1] = int64(math.Max(float64(dp[i][0] - a[i]), float64(dp[i][1] + a[i])))
  }
  fmt.Println(dp[n][0])
}


Measured memory_bytes: 7936
N = 8 # クイーンの数
n = int(input())

raw = [-1 for i in range(N)]
col = [0 for i in range(N)] # FREE: 0, NOT_FREE: 1
dpos = [0 for i in range(2*N-1)] # FREE: 0, NOT_FREE: 1
dneg = [0 for i in range(2*N-1)] # FREE: 0, NOT_FREE: 1


def put_queen(i):
	if i == N:
		return True
	elif raw[i] != -1:
		if put_queen(i+1):
			return True
		else :
			return False
	else:
		for j in range(N):
			if col[j] == 1 or dpos[i+j] == 1 or dneg[i-j+N-1] == 1:
				continue
			raw[i] = j
			col[j] = dpos[i+j] = dneg[i-j+N-1] = 1
			if put_queen(i+1):
				return True
			else :
				raw[i] = -1
				col[j] = dpos[i+j] = dneg[i-j+N-1] = 0
		return False


def output_result():
	for i in range(N):
		out_raw = ['.' for i in range(N)]
		out_raw[raw[i]] = 'Q'
		print(''.join(map(str, out_raw)))


for i in range(n):
	r, c = map(int, input().split())
	raw[r] = c
	col[c] = dpos[r+c] = dneg[r-c+N-1] = 1

put_queen(0)
output_result()


Measured memory_bytes: 5616
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;

LL dp[1145][14];

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

	int a;
	if (s[0] == 'J')a = 2;
	else if (s[0] == 'O')a = 1;
	else if(s[0]=='I')a = 0;

	for (int i = 4;i<8;i++) {
		if ((i&(1<<a))!= 0) {
			dp[1][i] = 1;
		}
	}

	for (int i = 2;i <= n;i++) {
		int b;

		if (s[i - 1] == 'J')b = 4;
		else if (s[i - 1] == 'O')b = 2;
		else b = 1;

		for (int j = 1;j < 8;j++) {//today
			for (int k = 1;k < 8;k++) {//tomorrow
				if ((j&k) != 0) {
					if ((k&b)!=0) {
						dp[i][k] += dp[i - 1][j]%10007;
					}
				}
			}
		}
	}

	LL ans = 0;
	for (int i = 0;i<8;i++) {
		ans += dp[n][i];
		ans %= 10007;
	}
	cout << ans % 10007 << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 3300
#include "bits/stdc++.h"
using namespace std;

int main() {
	int D, C[26];
	cin >> D;
	for (int i = 0; i < 26; i++) cin >> C[i];
	vector<int> L(26, -1);
	vector<vector<int> > S(D, vector<int>(26));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) cin >> S[i][j];
	}
	for (int i = 0; i < D; i++) {
		long long MAX = -1000000000000000, ID = -1;
		for (int j = 0; j < 26; j++) {
			if (MAX < S[i][j] + C[j] * 7 * (i - L[j])) MAX = S[i][j] + 7 * C[j] * (i - L[j]), ID = j;
		}
		L[ID] = i;
		cout << ID + 1 << endl;
	}
}

Measured memory_bytes: 3672
#include<stdio.h>
void main()
{
  int N,l,change;
  scanf("%d",&N);
  l=N%1000; 
  change=1000-l;
  if(l!=0){
    printf("%d\n",change);
  }
  if(l==0){
    printf("%d",0);
  }
 }
  

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

int main(){
  ll n,ans=0;
  cin >> n;
  ans = n*(n+1)/2;
  ans -= (n/3)*(n/3+1)/2*3;
  ans -= (n/5)*(n/5+1)/2*5;
  ans += (n/15)*(n/15+1)/2*15;
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,ans=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=1;i<n-1;i++)
        ans+=((v[i-1]<v[i]&&v[i]<v[i+1])||(v[i-1]>v[i]&&v[i]>v[i+1]));
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	
	int ans = 1;
	
	rep(i,n){
		cin >> s.at(i);
	}
	
	sort(s.begin(), s.end());
	
	string mem = s.at(0);
	for(int i = 1; i < n; i++){
		if(mem != s.at(i)){
			ans++;
			mem = s.at(i);
		}
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 9572
#include <bits/stdc++.h>
using namespace std;
int n, k, c;
int so(string s1){
	int n1 = s1.size();
	int count = 0;
	for(int i = 0;i < n1;i++){
		if(s1[i] == 'o'){
			count++;
			i += c;
		}
	}
	return count;
}
int main(){
	int count = 0, count2 = 0;
	int c1[400000];
	int c2[400000];
	cin >> n >> k >> c;
	string s;
	cin >> s;
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	for(int i = 0;i < n;i++){
		if(s[i] == 'o'){
			count++;
			c1[i] = count;
			for(int j = 0;j < c;j++){
				i++;
				c1[i] = count;
			}
		}else{
			c1[i] = count;
		}
	}
	for(int i = n - 1;i >= 0;i--){
		if(s[i] == 'o'){
			count2++;
			c2[i] = count2;
			for(int j = 0;j < c;j++){
				i--;
				c2[i] = count2;
			}
		}else{
			c2[i] = count2;
		}
	}
	if(c2[1] < k){
		cout << 1 << endl;
	}
	for(int i = 1;i < n - 1;i++){
		if((c1[i - 1] + c2[i + 1]) < k){
			cout << i + 1 << endl;
		}
	}
	if((c1[n - 2]) < k){
		cout << n << endl;
	}
}

Measured memory_bytes: 4612
#include <stdio.h>
#include <ctype.h>
char c[1200];
int cnt[27];
int main()
{
    char ch;
    int n;
    while(scanf("%s", c) != EOF) {
        for (int i = 0; c[i] != '\0'; ++i) {
            ch = tolower(c[i]);
            n = ch - '0';
            if (n < 49 || n > 74) continue;
            ++cnt[n-49];
        }
    }
    for (int i = 0; i < 26; ++i) printf("%c : %d\n", i + 97, cnt[i]);
    return 0;
}



Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100;
#define ll long long

ll v[N];

ll C(ll n){
    return n*(n-1)/2;
}

struct node{
    ll cnt,id;
};

ll sum=0;
void solve(){
    int n;
    scanf("%d",&n);
    vector<node> a(n+1);
    for(int i=1;i<=n;i++){
        ll x;
        scanf("%lld",&x);
        a[x].cnt++;
        a[x].id=x;
        v[i]=x;
    }
    for(int i=1;i<=n;i++){
        if(a[i].cnt==0)continue;
        sum+=C(a[i].cnt);
    }
    for(int i=1;i<=n;i++){
        ll ans=sum;
        ans-=C(a[v[i]].cnt);
        ans+=C(a[v[i]].cnt-1);
        printf("%lld\n",ans);
    }
}

int main(){
    solve();
}


Measured memory_bytes: 7296
#include"bits/stdc++.h"
using namespace std;

void print(vector<int>& S)
{
	for(int i = 1; i < S.size(); i++)
	{
		cout << "node " << (i) << ": key = " << S[i] << ", ";
		if(i != 1) cout << "parent key = " << S[(i/2)] << ", ";
		if((i*2) <= S.size() - 1) cout << "left key = " << S[i*2] << ", ";
		if(((i*2)+1) <= S.size()-1) cout << "right key = " << S[i*2+1] << ", ";
		cout << endl;
	}
}

int main(void)
{
	int N;
	cin >> N;
	N += 1;
	vector<int> S(N);
	for(int i = 1; i < N; i++) cin >> S[i];

	print(S);

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res;
ll mod = 1000000000 + 7;
int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N, K;
    ll ans = 0;
    cin >> N >> K;

    for (long long i = K; i <= N + 1; i++)
        ans = (ans + i * (N - i + 1) + 1) % 1000000007;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

const int N = 11;
int dp[N][10] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    for (int i = 0; i < 10; i++) {
        dp[1][i] = 1;
    }
    for (int i = 2; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = max(0, j - 1); k <= min(9, j + 1); k++) {
                dp[i][j] += dp[i - 1][k];
            }
        }
    }
    auto cnt = [&] (int len) {
        int ans = 0;
        for (int j = 1; j < 10; j++) ans += dp[len][j];
        return ans;
    };
    int len = 1;
    while (cnt(len) < k) {
        k -= cnt(len);
        ++len;
    }
    int last = -1;
    for (int i = 0; i < len; i++) {
        for (int j = !bool(i); j < 10; j++) {
            if (last != -1 && abs(last - j) > 1) continue;
            if (k > dp[len - i][j]) {
                k -= dp[len - i][j];
            }
            else {
                cout << j;
                last = j;
                break;
            }
        }
    }
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  vector<int>A;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0'){
      A.push_back(0);
    }
    else if(S.at(i)=='1'){
      A.push_back(1);
    }
    else{
      if(A.size()==0){
      }
      else{
        A.pop_back();
      }
    }
  }
  for(int i=0;i<A.size();i++){
    cout<<A.at(i);
  }
}

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

int main() {

	int H;
	std::cin >> H;

	int A;
	std::cin >> A;

	int b;

	for (int i = 1; H > 0; ++i) {
		H -= A;
		b = i;
	}

	std::cout << b << std::endl;

	return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c) #使わない
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10 #合成
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include<stdio.h>
 
int main(void)
{
   int a, b;
   scanf("%d %d", &a, &b);
   if(a < b){
     printf("a < b\n");
   }else if(a > b){
     printf("a > b\n");
   }else{
     printf("a == b\n");
   }
   return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

#define MAX 114

vector<int> G[MAX];
int col[MAX];
bool found;

void dfs(int v)
{
    col[v] = 0;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
        int to = G[v][i];
        if(col[to] == -1){
            dfs(to);
        }else if(col[to] == 0){
            found = true;            
            return;
        }
    }
    col[v] = 1;
}
    
int main()
{
    int M, N;
    cin >> M >> N;
    
    auto canGraph = [=](){
        int l[MAX][MAX], u[MAX][MAX];
        for(int i = 0 ; i < MAX ; i++){
            for(int j = 0 ; j < MAX ; j++){
                l[i][j] = -1;
                u[i][j] = 101;
            }
        }
        int K, s, t;
        string c;
        bool poss = 1;
        for(int i = 0 ; i < M ; i++){
            cin >> K;
            for(int j = 0 ; j < K ; j++){
                cin >> s >> c >> t;
                --s;
                if(c == ">="){
                    l[i][s] = max(l[i][s], t);
                }else{
                    u[i][s] = min(u[i][s], t);
                }
            }
            for(int j = 0 ; j < N ; j++){
                if(l[i][j] > u[i][j]){
                    poss = 0;
                    break;
                }
            }
        }

        if(!poss) return false;

        auto isConnect = [=](int from, int to){
            for(int i = 0 ; i < N ; i++){
                if(u[from][i] <= l[to][i]){
                    return true;
                }
            }
            return false;
        };
        
        for(int from = 0 ; from < M ; from++){
            for(int to = 0 ; to < M ; to++){
                if(from == to) continue;
                if(isConnect(from, to)){
                    G[from].push_back(to);
                }
            }
        }
        found = false;
        memset(col, -1, sizeof(col));
        for(int i = 0 ; i < M ; i++){
            if(col[i] == -1){
                dfs(i);
            }
        }                                       
        return !found;
    };
    
    cout << (canGraph() ? "Yes" : "No") << endl;
    return 0;
}

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

using std::cerr;
using std::endl;

const int N = 505;

int n;
long long A[N][N];
long long B[N][N];
long long f[N][N];
long long ans;

inline long long get_val(int k, int j, int i) {
  long long ret1 = B[j + 1][i];
  long long ret2 = A[n][j] - A[n][k] - A[i][j] + A[i][k];
  return ret1 + ret2;
}

int main() {
//   freopen("data", "r", stdin);
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j)
        std::cin >> A[i][j];
  for (int j = 1; j <= n; ++j)
    for (int i = j; i; --i)
      B[i][j] = B[i + 1][j] + B[i][j - 1] - B[i + 1][j - 1] + A[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      A[i][j] += A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1];
  ans = 1e18;
  for (int i = 1; i < n; ++i) {
    f[i][0] = get_val(0, 0, i);
    ans = std::min(ans, f[i][0] + get_val(0, i, n));
    for (int j = 1; j < i; ++j) {
      f[i][j] = 1e18;
      for (int k = 0; k < j; ++k) {
        f[i][j] = std::min(f[i][j], f[j][k] + get_val(k, j, i));
      }
      ans = std::min(ans, f[i][j] + get_val(j, i, n));
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 6272
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
M = 10 ** 6

B = Counter(A)
C = list(B.keys())
C.sort()

table = [1] * (M + 1)
cnt = 0
for c in C:
    if B[c] == 1:
        if table[c] == 1:
            cnt += 1
    for i in range(M):
        if c * i > M:
            break
        else:
            table[c * i] = 0

print(cnt)


Measured memory_bytes: 119236
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, x;
vector<lli> a;
int main() {
  cin >> n >> x; read_n(a, n);
  sort(begin(a), end(a));
  lli ans = 0;
  for (lli i=0; i<n; ++i) {
    x -= a[i];
    if (x>=0) ++ans;
  }
  if (x>0) --ans;
  cout << ans << endl;
  return 0;
}



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

using namespace std;

typedef long long ll;

int main(void) {
  int N; cin >> N;
  int A[2][100];
  for (int i = 0; i < N; i++) { cin >> A[0][i]; }
  for (int i = 0; i < N; i++) { cin >> A[1][i]; }


  int maxI = 0;
  for (int i = 0; i < N; i++) {
    int lI = 0;
    for (int j = 0; j <= i; j++)
      lI += A[0][j];
    for (int j = i; j < N; j++)
      lI += A[1][j];
    // cout << i << " " << lI << endl;
    maxI = max(maxI, lI);
  }

  cout << maxI << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
const int MAX = 100000;
const int MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main(){
    COMinit();
    ll N, K, ans, com1, com2;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);
    sort(A.begin(), A.end());
    ans = 0;
    
    for (int i = 0; i < N; i++) {
        com1 = COM(N - i - 1, K - 1);
        com2 = COM(i, K - 1);
      
        ans -= com1 * A.at(i);
        ans += com2 * A.at(i);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
/*
 * abc152a.cpp
 * Copyright (C) 2020 itachi <itachi@itachi-Z510>
 *
 * Distributed under terms of the MIT license.
 */

#include <bits/stdc++.h>

using namespace std;

int main() {
    int m,n;
    cin >> n >> m;
    cout << (m==n ? "Yes": "No") << endl;
}


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

int number(string const& s, int i, int& p) {
    int res = 0;
    while(p < s.size() && (isdigit(s[p]) || s[p] == 'X')) {
        res *= 10;
        if(s[p] == 'X') {
            res += i;
        } else {
            res += s[p] - '0';
        }
        p++;
    }
    return res;
}

int main() {
    string s;
    while(cin >> s) {
        bool leading = s[0] == 'X' && s[1] != '+'
                       || s[s.find('+')+1] == 'X' && s[s.find('+')+2] != '='
                       || s[s.find('=')+1] == 'X' && s.find('=') != s.size()-2;
        int p = 0, n1 = 0, n2 = 0;
        int res = -1;
        for(int i=leading; i<10; ++i) {
            p = 0;
            int n1 = number(s, i, p);
            int n2 = number(s, i, ++p);
            int n3 = number(s, i, ++p);
            if(n1 + n2 == n3) {
                res = i;
                break;
            }
        }
        if(res == -1) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 3184
// C++ program to find the longest repeated 
// non-overlapping substring 
#include<bits/stdc++.h> 
using namespace std; 
  
// Returns the longest repeating non-overlapping 
// substring in str 
string longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 
  
    // Setting all to 0 
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res; // To store result 
    int res_length  = 0; // To store length of result 
  
    // building table in bottom-up manner 
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        { 
            // (j-i) > LCSRe[i-1][j-1] to remove 
            // overlapping 
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
  
                // updating maximum length of the 
                // substring and updating the finishing 
                // index of the suffix 
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
  
    // If we have non-empty result, then insert all 
    // characters from first character to last 
    // character of string 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
  
    return res; 
}

// Driver program to test the above function 
int main() { 
    int n; string str;
    cin>>n>>str;
    cout << longestRepeatedSubstring(str).size() <<endl; 
    return 0; 
} 

Measured memory_bytes: 97920
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target ("sse4")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define rall(vec) (vec).rbegin(), (vec).rend()
#define piiii pair<pair<int, int>, pair<int, int>>
struct kek{
    int a,b,c,d;
};




vector<kek> arr;
int ans=0;
void gogo(int n, int m, int kolvo, vector<int> &now, int last){
    if(kolvo==n){
        int sm=0;
        for(int j=0;j<arr.size();j++){
            if(now[arr[j].b-1]-now[arr[j].a-1]==arr[j].c){
                sm+=arr[j].d;
            }
        }
        ans=max(ans, sm);
        return;
    }
    for(int i=last;i<=m;i++){
        now[kolvo]=i;
        gogo(n,m,kolvo+1, now, i);
    }

}
void solve() {
    int x;
    cin>>x;
    for(ll i=-200;i<=200;i++){
        for(ll j=-200;j<=200;j++){
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout<<i<<" "<<j<<endl;
                return;
            }
        }
    }

}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    int n, m, r = 0; cin >> n >> m;
    vector<int> h(n);
    vector<bool> x(n, true);
    rep(i, n) cin >> h[i];
    rep(i, m) {
        int a, b; cin >> a >> b; a--; b--;
        if (h[a] > h[b]) {
            x[b] = false;
        }
        else if (h[b] > h[a]) {
            x[a] = false;
        }
        else {
            x[a] = false;
            x[b] = false;
        }
    }
    rep(i, n) {
        if (x[i]) {
            r++;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;

int a[1000001],n;
int f[1000001];
int fr[1000001];

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i],fr[a[i]]++;
    
    int g=a[1];
    for(int i=2;i<=n;i++){
        g=__gcd(g,a[i]);
    }
    if(g!=1){
        cout<<"not coprime";
        return 0;
    }
    
    for(int i=2;i<=1e6;i++){
        for(int j=i;j<=1e6;j+=i){
            f[i]+=fr[j];
        }
        if(f[i]>1){
            cout<<"setwise coprime";
            return 0;
        }
    }
    
    cout<<"pairwise coprime";
    
}

Measured memory_bytes: 19832
/* ex3_2
   moka223711 */

#include <stdio.h>

int main(void){
  int N;
  scanf("%d", &N);
  
  switch(N % 10){
    case 2: case 4: case 5: case 7: case 9:
      printf("hon");
      break;
    case 0: case 1: case 6: case 8:
      printf("pon");
      break;
    default:
      printf("bon");
  }
  
  return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

const int max_n=100,max_w=10;

int main(){
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i,n){
        cin >> w[i];
    }
    bool flag=true;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(w[i]==w[j]){
                flag=false;
                break;
            }
        }
    }
    rep(i,n-1){
        if(w[i][w[i].size()-1]==w[i+1][0]){
            continue;
        }else{
            flag=false;
            break;
        }
    }
    if(flag) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

// 二分累乗法
template <typename T>
T modpow(T a, T n, T mod) {
    T ret = 1;

    if (mod == 1) {
        while (n > 0) {
            if (n & 1) {
                ret = ret * a;
            }
            a = a * a;
            n >>= 1;
        }
    } else {
        while (n > 0) {
            if (n & 1) {
                ret = ret * a % mod;
            }
            a = a * a % mod;
            n >>= 1;
        }
    }

    return ret;
}

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

    int n;
    cin >> n;
    int ro = 100001;
    vector<int> m(100001);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m[a]++;
    }

    int cnt = 0;
    for (int i = 1; i < ro; i++) {
        if (m[i]) {
            cnt++;
        }
    }

    int ans;
    if (cnt % 2 == 0) {
        ans = cnt - 1;
    } else {
        ans = cnt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3728
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple> 
#include <memory>
#include <random>
#include <iterator>
#include <cassert>
using namespace std;

int main(void){
   int n; cin >> n;
   vector<int>l(n);
   for (int i = 0; i < n; i++) {
        cin >> l[i];   
   }
   
   sort(l.begin(), l.end(), std::greater<int>() );
   int sum = 0;
   for (int i = 1; i < n; i++) {
       sum += l[i];
   }
   
   if (l[0] < sum) cout << "Yes";
   else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,ans=0,mm;
    cin >> n >> k;
    rep(i,k,n+1){
        mm=(2*n-i+1)*i/2-(i-1)*i/2+1;
        ans=(ans+mm)%mod;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
vector<int> edge;
long long N;
long long ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for(long long  i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    edge.emplace_back(tmp);
  }

  std::sort(begin(edge), end(edge));
  for(long long i = N -1; i >= 0; --i) {
    for(long long j = i -1; j >= 0; --j) {
      auto it = std::lower_bound(begin(edge), end(edge), edge[i] - edge[j] + 1);
      if(distance(begin(edge), it) < j){
        long long dist = std::distance(it, end(edge));
        ans += dist - (N  - j);
      }
    }
  }
  std::cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int N;
int main() {
  scanf("%d", &N);
  int max = 0, skip = 0;
  for(int i = 1, sum = 0; i <= N; ++i) {
    sum += i;
    if(sum >= N) {
      max = i;
      skip = sum-N;
      break;
    }
  }
  for(int i = 1; i <= max; ++i) {
    if(i == skip) continue;
    printf("%d\n", i);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;


class QuickSort
{
public:
  int n;
  pair<char,int> *a;
  QuickSort( int x );
  int partition( int p, int r );
  int sort( int p, int r );
};

QuickSort::QuickSort( int x ) : n(x)
{
  a = new pair<char,int> [x];
}

int QuickSort::partition( int p, int r )
{
  int x = a[r].second;
  int i = p - 1;

  for ( int j = p; j < r; j++ )
    {
      if ( a[j].second <= x )
        {
          ++i;
          swap( a[i], a[j] );
        }
    }
  swap( a[i+1], a[r]);
  
  return i+1;
}

int QuickSort::sort( int p, int r )
{
  if ( p < r )
    {
      int q = partition( p, r );
      sort( p, q - 1 );
      sort( q + 1, r );
    }

  return 0;
}

class MergeSort
{
public:
  int n;
  pair<char,int> *a;
  MergeSort( int x );
  int merge( int left, int mid, int right );
  int sort( int left, int right );
};

MergeSort::MergeSort( int x ) : n(x)
{
  a = new pair<char,int> [x];
}

int MergeSort::merge(int left, int mid, int right)
{
  const pair<char, int> infty = make_pair('X', 2000000000);
  int n1 = mid - left;
  int n2 = right - mid;

  pair<char,int> *l = new pair<char,int> [n1 + 1];
  pair<char,int> *r = new pair<char,int> [n2 + 1];

  for ( int i = 0; i < n1; i++ )
    l[i] = a[left + i];
  
  for ( int i = 0; i < n2; i++ )
    r[i] = a[mid + i];

  l[n1] = infty;
  r[n2] = infty;

  int i = 0;
  int j = 0;

  for ( int k = left; k < right; k++ )
    {
      if ( l[i].second <= r[j].second )
        a[k] = l[i++];
      else
        a[k] = r[j++];
    }

  delete[] l;
  delete[] r;
  
  return 0;
}

int MergeSort::sort( int left, int right )
{
  int mid;

  if ( left + 1 < right )
    {
      mid = (left + right) / 2;
      sort( left, mid );
      sort( mid, right );
      merge( left, mid, right );
    }
  
  return 0;
}

int main()
{

  bool stable;
  int n;
  cin >> n;

  char m;
  int v;
  pair<char,int> c;
  
  QuickSort qs(n);
  MergeSort ms(n);
  
  for ( int i = 0; i < n; i++ )
    {
      cin >> m >> v;
      c = make_pair(m, v);
      qs.a[i] = c;
      ms.a[i] = c;
    }
  
  qs.sort( 0, n-1 );
  ms.sort( 0, n );
  
  stable = true;
  
  for ( int i = 0; i < n; i++ )
    {
      if ( qs.a[i] != ms.a[i] )
        {
          stable = false;
          break;
        }
    }

  if ( stable )
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;
  
  for ( int i = 0; i < n; i++ )
    cout << qs.a[i].first << " " << qs.a[i].second << endl;
  
  return 0;
}

Measured memory_bytes: 3356
#include <iostream>
using namespace std;
constexpr int MAX=1000000;
constexpr int NIL=-1;

struct Node{int parent, left, right;};
Node T[MAX];
int n, D[MAX];

void print(int u){
   int i, c;
   cout << "node " << u << ": ";
   cout << "parent = " << T[u].parent << ", ";
   cout << "depth = " << D[u] << ", ";

   if(T[u].parent == NIL) cout << "root, ";
   else if(T[u].left == NIL) cout << "leaf, ";
   else cout << "internal node, ";
   
   cout << "[";

   for(i=0, c=T[u].left; c!=NIL; i++, c=T[c].right){
      if(i) cout << ", ";
      cout << c;
   }
   cout << "]" << endl;
}

int rec(int u, int p){
   D[u]=p;
   if(T[u].right!=NIL) rec(T[u].right, p);
   if(T[u].left!=NIL) rec(T[u].left, p+1);
}

int main(){
   int i, j, d, v, c, l, r;
   cin >> n;
   for(i=0; i<n; i++) T[i].parent = T[i].left = T[i].right = NIL;
   for(i=0; i<n; i++){
      cin >> v >> d;
      for(j=0; j<d; j++){
         cin >> c;
         if(j==0) T[v].left=c;
         else T[l].right=c;
         l=c;
         T[c].parent=v;
      }
   }
   for(i=0; i<n; i++){
      if(T[i].parent==NIL) r=i;
   }

   rec(r, 0);

   for(i=0; i<n; i++) print(i);

   return 0;
}


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

int main()
{
  int h,w;
  cin >> h >> w;
  int a[h][w];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin >> a[i][j];
  int mi=10000000;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int s=0;
      for(int k=0;k<h;k++)
        for(int l=0;l<w;l++){
          s+=a[k][l]*min(abs(k-i),abs(l-j));
        }
      mi=min(mi,s);
    }
   cout << mi << endl;
  return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
//#define int long long
using namespace std;
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
//const int INF = 1e10 ;

int dp[N][3], mat[N][3];

int32_t main() {
	fast;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a, b, c;
		cin>>a>>b>>c;
		mat[i][0] = a;
		mat[i][1] = b;
		mat[i][2] = c;
	}
	dp[0][0] = mat[0][0], dp[0][1] = mat[0][1], dp[0][2] = mat[0][2];
	for(int i=1;i<n;i++){
		dp[i][0] = mat[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = mat[i][1] + max(dp[i-1][2], dp[i-1][0]);
		dp[i][2] = mat[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}




Measured memory_bytes: 5924