akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = 998244353;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 200100


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

	int n, k;
	cin >> n >> k;
	vi a(n + 1), dp(n + 1, oo);


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

	a[0] = a[1];
	dp[1] = 0;
	for (int i = 2; i <= n; i++)
	{
		for (int j = i - 1; j >= max(i - k, 1LL); j--) 
			inmin(dp[i], dp[j] + abs(a[i] - a[j]));
	}
	cout << dp[n];


}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	int a[101];
	double t=0;
	double r=100000;
	int l=0;

	cin>>n;
	rep(i,n){
		cin>>a[i];
		t+=a[i];
	}
	t=t/n;
	rep(i,n){
		if(abs(a[i]-t)<r){
			l=i;
			r=abs(a[i]-t);
		}
	}
	cout<<l<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.21 21:13:07
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    string ans;
    while (n) {
        n--;
        ans.push_back('a' + n % 26);
        n /= 26;
    }
    for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pic pair<int,char>

int H,W,g1,g2,g4;
string S;
priority_queue<pic> Q;
map<char, int> mp;

bool solve(){
    int m = H/2, n = W/2;
    g4 = m * n;

    if(H%2 == 1 && W%2 == 1){
        g2 = m + n;
        g1 = 1;
    }else if (H%2 == 0 && W%2 == 0){
        g2 = 0;
        g1 = 0;
    } else {
        if(H%2==0)
            g2 = H;
        else
            g2 = W;
        g2 /= 2; 
        g1 = 0;
    }

    pic tmp;
    char key;
    int val;

    // printf("(g4,g2,g1) = (%d,%d,%d)\n",g4,g2,g1);

    rep(i, g4){
        tmp = Q.top();
        key = tmp.second, val = tmp.first;
        Q.pop();
        if(val < 4)
            return false;
        val -= 4;
        Q.push(pic(val,key));
    }

    rep(i, g2){
        tmp = Q.top();
        key = tmp.second, val = tmp.first;
        Q.pop();
        if(val < 2)
            return false;
        val -= 2;
        Q.push(pic(val,key));
    }

    rep(i, g1){
        tmp = Q.top();
        key = tmp.second, val = tmp.first;
        Q.pop();
        if(val < 1)
            return false;
        val -= 1;
        Q.push(pic(val,key));
    }

    return true;
}

int main(){
    cin >> H >> W;

    rep(i,H){
        cin >> S;
        rep(j,W)
            mp[S[j]]++;
    }

    for (auto itr=mp.begin(); itr!=mp.end();++itr)
        Q.push(pic(itr->second, itr->first));

    if(solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/

int main(){

	string s; cin >> s;

	if (s[0] == s[1] || s[2] == s[1] || s[2] == s[3]) { cout << "Bad" << endl; }
	else {
		cout << "Good" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

for i in range(1, 101):
    HP = C - (B*i)
    if HP < 0 or HP == 0:
        print("Yes")
        break
    else:
        HP2 = A - (D*i)
        if HP2 < 0 or HP2 == 0:
            print("No")
            break

Measured memory_bytes: 9192
#include <iostream>
#include <cstdlib> //絶対値abs
#include <algorithm> //minmax
using namespace std;
int N,K;
long long h[100010];
long long dp[100010];
const long long INF = 1LL << 62;
int main(){
	cin >> N >>K;
	for (int i = 0; i < N; ++i){
		cin >> h[i];
	}
	for (int i = 0; i < 100010; ++i) dp[i] = INF;

	dp[0] = 0;

	for (int i = 0; i < N; ++i){
		for (int j = 1; j <= K; ++j){
			dp[i+j]= min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
		}
	}

	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main() {
  int A, B;
  std::cin >> A >> B;
  if (A + B == 15) {
    std::cout << "+" << std::endl;
  } else if (A * B == 15) {
    std::cout << "*" << std::endl;
  } else {
    std::cout << "x" << std::endl;
  }
  return EXIT_SUCCESS;
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;

int dp[N][3] = {};
int a[N] = {};
int b[N] = {};
int c[N] = {};

int main() {

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

	int n;
	cin >> n;
	f(i, 1, n + 1) cin >> a[i] >> b[i] >> c[i];

	f(i, 1, n + 1) {
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << nl;
}

Measured memory_bytes: 5972
#include <iostream>
#include <iomanip>
#include <vector>
#include <complex>
#include <cmath>
using namespace std;
using xy_t = complex<double>;

int main(){
  vector<xy_t> V;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    double x_in, y_in;
    cin >> x_in >> y_in;
    V.push_back(xy_t(x_in, y_in));
  }
  double sum = 0.0;
  for(int i=1;i<n-1;i++){
    xy_t vec[2] = {V[i] - V[0], V[i+1] - V[0]};
    sum += (conj(vec[0]) * vec[1]).imag() * 0.5;
  }
  cout << fixed << setprecision(1) << sum << endl;
}


Measured memory_bytes: 3280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
  char str[15];
  int val,money,count;
  scanf("%s",str);
  sscanf(str,"%d",&val);
  scanf("%s",str);
  sscanf(str,"%d",&money);
  scanf("%s",str);
  sscanf(str,"%d",&count);
  if(count*val <= money){
    printf("%d",count); //満足するまで聞ける
  }
  else{
    printf("%d",money/val); //お金がある分だけ聞ける
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
using namespace std;
//とりまイントとダブルが入り乱れるときは
//とりまどちらかに統一しよう。

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int min(int x,int y){
  if(x<y) return x;
  return y;
}

int main() {
  int k,s;
  cin >> k >> s;
  int res = 0;
  bool judge=false;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= k; ++y) {
      int z = s - x - y; // 合計
      if (0<=z&&z<=k) res++;
    }
  }
  cout << res << endl;
}


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n, k;
    cin >> n >> k;

    long ans = k * pow(k - 1, n - 1);
    cout << ans << endl;
}


Measured memory_bytes: 4024
import java.util.Scanner;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.Collections;
import java.io.PrintWriter;

public class Main {
  static int N;
  static int Q;
  static ArrayList<S> ss;
  static PrintWriter writer = new PrintWriter(System.out);
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    N = Integer.parseInt(sc.next());
    Q = Integer.parseInt(sc.next());
    ss = new ArrayList<S>();
    for (int i = 0; i < N; i++){
      int s = Integer.parseInt(sc.next());
      int t = Integer.parseInt(sc.next());
      int x = Integer.parseInt(sc.next());
      ss.add(new S(x,s-x,-1));
      ss.add(new S(x,t-x,-2));            
    }
    for (int i = 0; i < Q; i++) {
      int d = sc.nextInt();
      ss.add(new S(-1,d,i));
    }
    Collections.sort(ss);
    TreeSet<Integer> cons = new TreeSet<>();
    int[] ans = new int[Q];
    for (int i =0; i<ss.size(); i++) {
      S s = ss.get(i);
      if (s.index == -1) {
        cons.add(s.x);        
      } else if (s.index == -2) {
        cons.remove(s.x);        
      } else {
        ans[s.index] = cons.isEmpty() ? -1 : cons.first();
      }
    }
    for (int i = 0; i < Q; i++) {
      writer.println(ans[i]);
    }
    writer.flush();
  }
  public static class S implements Comparable<S> {
    int x;
    int t;
    int index;
    public S(int x, int t, int index) {
      this.x = x;
      this.t = t;
      this.index = index;
    }
    public int compareTo(S o){
      int dt = this.t- o.t;
      if (dt != 0) {
        return dt;
      } else {
        return this.index - o.index;
      }
    }
  }
}


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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


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

    println((s.back() == s.front() ? "Yes" : "No"));
}

Measured memory_bytes: 3616
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();

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

void Main(){
    char c;
    cin >> c;
    if('a'<=c && c<= 'z'){
        cout << 'a' << el;
    }else{
        cout << 'A' << el;
    }
    // Failed to predict input format
}




Measured memory_bytes: 3636
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");

var N = Arr[0];
var A = Arr[1].split(" ").map(Number);


var selectionSort = (N,array) =>{
    
    let cnt = 0;
    
    for(let i = 0; i < N; i++){
        var minV = i;
        for(let j = i; j < N; j++){
            if(array[j] < array[minV]){
                minV = j;
                
            }
        }
        
      	if(i !== minV){
        	var tmp = array[i];
        	array[i] = array[minV];
        	array[minV] = tmp;
      	    cnt++;
        }
    }

    return cnt;
}


var answer = selectionSort(N,A);

console.log(A.join(" "));
console.log(answer);




Measured memory_bytes: 15416
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint x, y, a, b, c;
vector<lint> p, q, r;

int main() {
    cin >> x >> y >> a >> b >> c;
    p.resize(a), q.resize(b), r.resize(c);
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(p.begin(), p.end(), greater<lint>());
    sort(q.begin(), q.end(), greater<lint>());
    sort(r.begin(), r.end(), greater<lint>());
    vector<lint> greed;
    for (int i = 0; i < x; i++) {
        greed.push_back(p[i]);
    }
    for (int i = 0; i < y; i++) {
        greed.push_back(q[i]);
    }
    for (int i = 0; i < c; i++) {
        greed.push_back(r[i]);
    }
    sort(greed.begin(), greed.end(), greater<lint>());
    lint ans = 0;
    for (int i = 0; i < x + y; i++) {
        ans += greed[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 8688
n = gets.to_i

edges = []
g = Array.new(n+1){ [] }
(n-1).times do |i|
  a, b = gets.split.map(&:to_i)
  a, b = a.to_i, b.to_i
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  edges << [a,b] # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n+1){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [1] # 頂点1から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] == true # 探索済みの頂点なら見ない。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    # next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

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

#define INF (INT32_MAX/2)
#define MOD (1000000000+7)
#define MAX 100
#define MAXK 100000

int N, K;
int a[MAX];

long long dp[MAX + 1][MAXK + 1];

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

	for( int i = 0; i <= N; i++ ) {
		dp[i][0] = 1;
	}
	for( int i = 1; i <= N; i++ ) {
		int aa = a[i - 1];
		for( int j = 1; j <= K; j++ ) {
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			if( j > aa ) {
				dp[i][j] = (dp[i][j] - dp[i - 1][j - aa - 1] + MOD) % MOD;
			}
		}
	}

	long long ans = dp[N][K];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 78336
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
	string s;
	getline(cin, s);

	for (int i = 0; i < 4; ++i)
	{
		cout << s[i];
	}

	cout << " ";

	for (int i = 4; i < s.length(); ++i)
	{
		cout << s[i];
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
char s[N];
int main() {
	scanf("%s", s+1);
	int n = strlen(s+1);
	for (int i = 1; i <= n; i++) {
		if (s[i] != s[n - i + 1]) {
			puts("No");
			return 0;
		}
	}
	for (int i = 1; i <= (n - 1) / 2; i++) {
		if (s[i] != s[(n - 1) / 2 + 1 - i]) {
			puts("No");
			return 0;
		}
	}
	int len = n + (n + 3) / 2;
	for (int i = (n + 3) / 2; i <= n; i++) {
		if (s[i] != s[len - i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}

Int n;
Int ans;
int main(){
    cin >> n;
    vector<Int> c(n);
    for(int i = 0;i < n;i++)cin >> c[i];
    sort(c.rbegin(), c.rend());
    for(int i = 0;i < n;i++){
        Int left = i;
        if(left % 2)left += MOD;
        left /= 2;
        left++;
        if(left % 2)left += MOD;
        left /= 2;left %= MOD;
        ans += left * c[i] %MOD ;
        ans %= MOD;
    }
    ans *= mod_pow(2, 2*n);
    cout << ans % MOD << endl;
    
    return 0;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e5 + 4;

ll v[T];
ll suml1;
ll suml2;
ll sumr1;
ll sumr2;

ll calc() {
    return max({suml1,suml2,sumr1,sumr2})-min({suml1,suml2,sumr1,sumr2});
}

int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> v[i];

    int l = 0;
    int r = n-1;
    int m = n-3;

    suml1 = v[l];
    suml2 = 0;
    sumr1 = v[r-1];
    sumr2 = v[r];

    for(int i = 1; i <= m; i++) suml2 += v[i];
    while(l+1 < m and abs(suml2-suml1) >= abs((suml2-v[l+1])-(suml1+v[l+1]))) {
        suml2 -= v[l+1];
        suml1 += v[l+1];
        l++;
    }

    ll ans = calc();
    //cout << l << " " << m << " " << r << endl;
    //cout << suml1 << " " << suml2 << " " << sumr1 << " " << sumr2 << endl;
    m--;

    while(m > 0) {
        suml2 -= v[m+1];
        sumr1 += v[m+1];

        while(r-1 > m+1 and abs((sumr1-v[r-1])-(sumr2+v[r-1])) <= abs(sumr1-sumr2)) {
            sumr1 -= v[r-1];
            sumr2 += v[r-1];
            r--;
        }

        while(l > 0 and ((abs((suml1-v[l])-(suml2+v[l])) <= abs(suml1-suml2)) or l == m)) {
            suml1 -= v[l];
            suml2 += v[l];
            l--;
        }

        ans = min(ans,calc());
        m--;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
    long long k; cin >> k;
    long long l = 9 * k;
    if (k % 7 == 0) l /= 7;
    long long ans = -1;
    if (l % 2 != 0 && l % 5 != 0)
    {
        long long left = 1;
        for (long long i = 0; i < l; i++)
        {
            left = (left * 10) % l;
            if (left == 1)
            {
                ans = i + 1;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;


struct Problem{
    int n;
    vector<pair<int,int>> p;
    vector<int> csum,sum;
    Problem(LL n):n(n),p(n),csum(n+1),sum(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            cin >> p[i].first >> p[i].second;
        }
        sort(p.begin(),p.end());
        int ansmin,ansmax;
        priority_queue<int,vector<int>,greater<int>> pq;
        pq.push(1);
        for(int i=0; i<n; ++i){
            pq.push(p[i].second);
            if(pq.top()<=p[i].first) pq.pop();
            csum[i+1]++;
            int pos = lower_bound(p.begin(),p.end(),make_pair(p[i].second,0))-p.begin();
            csum[pos]--;
            sum[i]=pos-i-1;
        }
        ansmin=pq.size();
        for(int i=1; i<n; ++i){
            csum[i]+=csum[i-1];
        }
        DBG(csum)

        for(int i=0; i<n; ++i){
            csum[i]+=sum[i];
        }
        DBG(p)
        DBG(csum)
        ansmax=*max_element(csum.begin(),csum.begin()+n)+1;
        cout << ansmax << ' ' <<ansmin <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}

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

long long countSetBits(long long n)
{
	long long count = 0; 
	while (n) { 
		count += n & 1; 
		n >>= 1; 
	} 
	return count; 
}

long long getans(long long ans){
	long long result=0;
	if(ans==0) return result;
	while(ans){
		ans%=countSetBits(ans);
		result++;
	}
	return result;
}

long long modpow(long long x, long long n, long long m) {
	if (n == 0) return 1%m;
	long long u = modpow(x,n/2,m);
	u = (u*u)%m;
	if (n%2 == 1) u = (u*x)%m;
	return u;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n; cin>>n;
	string s; cin>>s;
	long long count=0;
	for(long long i=0;i<n;i++){
		if(s[i]=='1'){
			count++;
		}
	}
	long long ans=0,ans2=0;
	long long tempans;
	for(long long i=0;i<n;i++){
		//ans+=pow(2*(s[i]-'0'), n-i-1);
		if(s[i]=='1'){
			ans+=modpow(2, n-i-1 ,count+1);
			ans%=count+1;
			if(count-1>0){
				ans2+=modpow(2, n-i-1 ,count-1);
				ans2%=(count-1);
			}
		}
	}
	//cout<<ans<<" "<<count;
	for(long long i=0;i<n;i++){
		if(s[i]=='1'){
			if(count-1>0){
				tempans=ans2-modpow(2, n-i-1 ,count-1);
				tempans=(tempans%(count-1)+count-1)%(count-1);
			//cout<<tempans<<endl;
				tempans=getans(tempans);
				cout<<tempans+1<<"\n";
			}else{
				cout<<0<<"\n";
			}
		}else{
			tempans=ans+modpow(2, n-i-1 ,count+1);
			tempans=tempans%(count+1);
			tempans=getans(tempans);
			cout<<tempans+1<<"\n";
		}
	}
}

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

vector<vector<int>> graph;
vector<int> dist;
vector<bool> visited[4];

void dfs(int u, int depth, queue<int> &bfs, int dis)
{
    visited[depth][u] = 1;
    
    if (depth == 0)
    {
        dist[u] = dis;
        bfs.push(u);
        
        return;
    }
    
    for (int v : graph[u])
    {
        if (visited[depth - 1][v])
            continue;
        
        dfs(v, depth - 1, bfs, dis);
    }
}

void do_shit(int s)
{
    queue<int> bfs;
    bfs.push(s);
    
    while (!bfs.empty())
    {
        int u = bfs.front();
        bfs.pop();
        
        // cout << u << '\n';
        dfs(u, 3, bfs, dist[u] + 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    graph.resize(n);
    for (int i = 0; i != 4; ++i)
        visited[i].resize(n);
    dist.resize(n);
    
    for (int i = 0; i != m; ++i)
    {
        int u, v;
        cin >> u >> v;
        
        graph[u - 1].push_back(v - 1);
    }
    
    int s, t;
    cin >> s >> t;
    
    do_shit(s - 1);
    
    if (dist[t - 1] == 0)
        cout << -1 << '\n';
    else
        cout << dist[t- 1] << '\n';
    
    return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

void f(int n){
  string s[1100];

  rep(i,n){
    cin>>s[i];
  }
  vector<int> v[2100];

  rep(j,2100){
    rep(i,n){
      if(j>=s[i].size()) continue;
      if(s[i][j]=='.'&&'a'<=s[i][j+1]&&s[i][j+1]<='z'){
        s[i][j]='+';
        v[j].PB(i);
      }
    }
  }

  rep(i,2100){
    if(v[i].size()<2) continue;
    rep(j,v[i].size()-1){
      int a=v[i][j],b=v[i][j+1];
      bool flag=false;
      FOR(k,a+1,b){
        if(i>=s[k].size()) continue;
        if(s[k][i]=='.')
          s[k][i]='|';
        else{
          flag=true;
        }
      }
      if(flag){
        FOR(k,a+1,b){
          if(i>=s[k].size()) continue;
          if(s[k][i]=='|')
            s[k][i]='.';
        }
      }
    }
  }
  rep(i,n){
    rep(j,2100){
      if(j>=s[i].size()) continue;
      if(s[i][j]=='.') s[i][j]=' ';
    }
  }

  rep(i,n){
    cout<<s[i]<<endl;
  }
}




main(){
  int n;
  while(true){
    cin>>n;
    if(!n) break;
    f(n);
  }
}



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

typedef long long ll;

int main() {
    int N, M, a, b;
    cin >> N >> M;
    vector<bool> from1(N, false), fromN(N, false);
    rep(i, M) {
        cin >> a >> b;
        if (a == 1) from1[b] = true;
        if (b == N) fromN[a] = true;
    }
    rep(i, N) {
        if (from1[i] && fromN[i]) {
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 256
num=list(str(input()))
num=[int(n) for n in num]
cnt=len(num)-1
for i in range(2**cnt):
    ln=["-"]*cnt
    tl=num[:]
    for j in range(cnt):
        if ((i>>j)&1):
            ln[cnt-j-1]="+"
    ans=tl[0]
    for k in range(cnt):
        tl.insert(k*2+1,ln[k])
        if ln[k]=="+":
            ans+=tl[k*2+2]       
        else:
            ans-=tl[k*2+2]
    if ans==7:
        print("".join(map(str,tl))+"=7")
        break


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

int main()
{
	long long ans = 0;
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	for (int i = 1; i < n; i++)
	{
		if (v[i] < v[i - 1]) ans += v[i - 1] - v[i],v[i]=v[i-1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4040
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans = 0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}

//最大公約数
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a%b);
}

int VectorSum(vector<int> x) {
	int ans = 0;
	rep(i, x.size()) {
		ans += x[i];
	}
	return ans;
}

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}
		Parent[A] += Parent[B];
		Parent[B] = A;
	}
};





int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;



}



Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>


int main(int argc, char const *argv[]) {
    int N,T; std::cin >> N >> T;
    int t[N];

    for (size_t i = 0; i < N; i++) {
        std::cin >> t[i];
    }
    int s=0;

    for (size_t i = 0; i < N-1; i++) {
        s+= std::min(T,t[i+1]-t[i]);
    }

    s+=T;
    std::cout << s << '\n';



    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[n];
    rp(i,n) cin >> a[i];
    sort(a,a+n);
    cout << a[n-1] - a[0]<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
    int n;
    long long num=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0) continue;
        num+=i;
    }
    cout<<num;
}


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

using namespace std;

int p[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<bool> doz(10, false);
    for (int i = 0; i < m; ++i)
    {
        int x;
        cin >> x;
        doz[x] = true;
    }
    vector< vector<bool> > dp(5001, vector<bool>(10001, false));
    dp[0][0] = true;
    for (int i = 1; i < 10; ++i)
        if (doz[i])
            dp[1][p[i]] = true;
    for (int i = 1; i < 5001; ++i)
        for (int j = 1; j < 10001; ++j)
            if (dp[i][j])
                for (int k = 1; k < 10; ++k)
                    if (doz[k] && j + p[k] < 10001)
                        dp[i + 1][j + p[k]] = true;
    for (int dl = n / 2; dl >= 1; --dl)
    {
        int s = n;
        string x = "";
        bool ok = true;
        for (int i = 0; i < dl; ++i)
        {
            for (int j = 9; j >= 1; --j)
            {
                if (doz[j] && s - p[j] >= 0 && dp[dl - i - 1][s - p[j]])
                {
                    x += (char) (j + '0');
                    s -= p[j];
                    break;
                }
            }
            if (x.size() != i + 1)
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            cout << x;
            return 0;
        }
    }
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int a, b;
  char op;
  cin >> a >> op >> b;
  if(op == '+') cout << a+b << endl;
  else cout << a-b << endl;
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
struct citys
{
	int y;
	int pre;
	int cnt;
	int num;
}cyy[101010];
bool cmpp(citys a,citys b)
{
	if(a.pre == b.pre)
	{
		return a.y<b.y;
	}
	return a.pre<b.pre;
}
bool cmp(citys a,citys b)
{
	return a.num<b.num;
}
int main()
{
	
	int n,m;
	cin>>n>>m;
	for(int i = 1;i<=m;i++)
	{
		cin>>cyy[i].pre>>cyy[i].y;
	
		cyy[i].num = i;
	}
	sort(cyy+1,cyy+1+m,cmpp);
	int ct = 0,tmp = cyy[1].pre;
	for(int i= 1;i<=m;i++)
	{
		if(tmp == cyy[i].pre)
		{
			cyy[i].cnt  = ++ct;
		}
		else
		{
			ct = 1;
			cyy[i].cnt = ct;
			tmp = cyy[i].pre;
		}
		//cout<<cyy[i].pre<<" "<<cyy[i].y<<" "<<cyy[i].cnt<<endl;
	}
	sort(cyy+1,cyy+1+m,cmp);
	
	for(int i= 1;i<=m;i++)
	{
		cout.fill('0');cout.width(6);
		cout<<cyy[i].pre;
		cout.fill('0');cout.width(6);
		cout<<cyy[i].cnt<<endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

const int MAX = 1e6+10;
long long fac[MAX], finv[MAX], inv[MAX];

void combInit() {
    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 comb(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;
}

ll n, x, y;
string s;

int main() {
    cin >> x >> y;
    if ((2*y-x)%3 != 0 || (2*x-y)%3 != 0) {
        std::cout << 0 << '\n';
        return 0;
    }

    ll a = (2*y - x) / 3, b = (2*x - y) / 3;
    if (a < 0 || b < 0) {
        std::cout << 0 << '\n';
        return 0;
    }

    combInit();
    std::cout << comb(a+b, a) << '\n';

    return 0;
}


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

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long long i=n/(a+b);
  long long ans=i*a;
  long long sw=n%(a+b);
  if(sw>a)ans+=a;
  else ans+=sw;
  printf("%lld\n",ans);
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
//
int main(){
    int cnt[9];
    for(int i = 0;i < 9; i++) cnt[i] = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int cur;
        cin >> cur;
        if(cur / 400 >= 8){
            cnt[8]++;
        }else{
            cnt[cur / 400]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < 8; i++){
        if(cnt[i] > 0) ans++;
    }
    if(ans == 0) cout << 1;
    else cout << ans;
    cout <<" " << ans + cnt[8];
}


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

int main(){
  int i,j,op;
  string S;
  cin >> S;

  for(i=0;i<pow(2,S.size()-1);++i){
    int result = S.at(0)-'0';
    for(j=0;j<S.size()-1;++j){
      int digit;
      digit = (i >> j) & 1;

      if(digit == 0)
        result -= S.at(j+1)-'0';
      else
        result += S.at(j+1)-'0';
    }
    if(result == 7){
      op = i;
      break;
    }
  }
  cout << S.at(0);
  for(i=0;i<S.size()-1;++i){
    if((op >> i) & 1)
      cout << '+';
    else
      cout << '-';
    cout << S.at(i+1);
  }
  cout << "=7";
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;

struct Solver{
  int N;
  vector<vector<int>> A;
  set<pii> match;
  explicit Solver(int n, vector<vector<int>> a) : N(n), A(a){}
  //--------------------
  void check(int I){
    if(A[I].empty()) return;
    int J = A[I].back();
    if(A[J].back()==I){
      if(I>J){swap(I,J);}
      pii temp=make_pair(I,J);
      match.insert(pii(I, J));
    }
  }
  //--------------------
  void init(){
    for(int i=0; i<N; i++){
      check(i);
    }
  }
  //--------------------
  int solve(){
    int day=0;
    init();
    
    while(!match.empty()){
      set<pii> prev;
      prev.swap(match);
      for(auto p : prev){
        A[p.first].pop_back();
        A[p.second].pop_back();
        check(p.first);
        check(p.second);
      }
      day++;
    }
    for(int i=0; i<N; i++){
      if(!A[i].empty()){
        day = -1;
        break;
      }
    }
    return day;
  }
};

int main(){
  scanf("%d", &n);
  vector<vector<int>> a(n, vector<int>(n-1,0));
  for(int i=0; i<n; i++){
    for(int j=n-2; j>=0; j--){
      scanf("%d", &a[i][j]); a[i][j]--;
    }
  } 
  
  Solver solver(n,a);
  printf("%d\n", solver.solve());
}

Measured memory_bytes: 12032
n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
r = [[a[0], 1]]
c = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        r[-1][1] += 1
    else:
        r.append([a[i+1], 1])
for i in range(len(r)):
    if r[i][0] <= r[i][1]:
        ans += r[i][1] - r[i][0]
    else:
        ans += r[i][1]
print(ans)

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }

class UnionFind {
private:
  vector<int> par;
  vector<int> rnk;
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
public:
  UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; }
  void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } }
  bool same(int x, int y) { return find(x) == find(y); }
};

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

signed main() {
  int n;
  cin >> n;
  set<int> r;
  int f = 0;
  REP(_, n) {
    int a;
    cin >> a;
    if (a >= 3200) {
      f += 1;
    } else {
      r.insert(a / 400);
    }
  }
  int s = r.size();
  cout << max(s, 1) << " " << (s + f) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  bool up=false,down=false;
  bool head=true;
  int ans=0;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  REP(i,n-1){
    if(a[i]<a[i+1]){
      if(head){
        head = false;
        up = true;
        down = false;
        continue;
      }else{
        if(up && !down){
          continue;
        }else if(up && down){
          down = false;
          continue;
        }else{
          ans++;
          head = true;
          up = down = false;
        }
      }
    }else if(a[i]>a[i+1]){
      if(head){
        head = false;
        up = false;
        down = true;
        continue;
      }else{
        if(!up && down){
          continue;
        }else if(up && down){
          up = false;
          continue;
        }else{
          ans++;
          head = true;
          up = down = false;
        }
      }
    }else{
      if(head){
        head = false;
        up = true;
        down = true;
        continue;
      }else{
        continue;
      }
    }
  }
  ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

N = int(input())
wN = [input() for i in range(N)]

wN2 = list(set(wN))

if len(wN) != len(wN2):
    print('No')
    exit()

for i in range(1, N):
    if wN[i][0] != wN[i-1][-1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

//改善　改善

int main(){

    string S;
    cin >> S;
    
    vector<ll > posi(S.length(), 0); 

    vector<ll > table(S.length(), 0);

    ll count = 0;

    //流し込める量を数え上げ
    for(ll i = S.length() - 1 ; i >= 0; i--){

        if(S[i] == 'R'){
            count++;
            table[i] = count;
        }else{
            count = 0;
        }     
    }
    for(ll i = 0 ; i < S.length(); i++){
    
        if(S[i] == 'L'){
            count--;
            table[i] = count;
        }else{
            count = 0;
            continue;
        }    
    }

    /*
    for(ll i = 0; i < S.length() - 1; i++){
        cout << table[i] << " ";
    }
    cout << table[S.length() - 1] << endl;
    */

    //集計
    for(ll i = 0; i < S.length(); i++){
        if( table[i] % 2 == 0){
            posi[i + table[i]]++;
        }else{
            if(table[i] < 0){
                posi[i + table[i] + 1]++;
            }else{
                posi[i + table[i] - 1]++;
            }
            
        }      
    }


    for(ll i = 0; i < S.length() - 1; i++){
        cout << posi[i] << " ";
    }
    cout << posi[S.length() - 1] << endl;;



} 

Measured memory_bytes: 2176