akhauriyash/Code-Regression huggingface dataset:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
S = [sys.stdin.readline().rstrip() for _ in range(N)]

graph = [set() for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == '1':
            graph[i].add(j)
            graph[j].add(i)


def count(v1):
    # bfs
    groups = [INF] * N
    groups[v1] = 0

    vs = [v1]
    g = 0
    while vs:
        nexts = set()
        for v in vs:
            nexts |= graph[v]
        vs = set()
        for u in nexts:
            if groups[u] not in [g - 1, INF]:
                return -1
            if groups[u] == INF:
                groups[u] = g + 1
                vs.add(u)
        g += 1
    return g


# グループ 1 にするやつを決め打つ
# つながってるやつは+1
ans = -1
for v1 in range(N):
    ans = max(ans, count(v1))
print(ans)


Measured memory_bytes: 44524
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string w;
    cin >> w;
    int len = w.size(), i;
    int A[27] = {0};
    for(i=0;i<len;i++)
    {
        A[w[i] - 97]++;
    }
    for(i=0;i<26;i++)
    {
        if(A[i]%2!=0)
        break;
    }
    if(i==26)
    cout << "Yes";
    else
    cout << "No";
    return 0;
}

Measured memory_bytes: 3592
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, T, A;
    in3(N, T, A);

    vi H(N);
    inN(H, N);

    double min = 1000000000;
    int ans = -1;

    rep(i, N)
    {
        double tmp = abs(T - 0.006 * H[i] - A);

        if (chmin(min, tmp))
        {
            ans = i + 1;
        }
    }

    outl(ans);

    return 0;
}


Measured memory_bytes: 3580
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int key) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = new Node;
    z->key = key;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node *find(Node *u, int key) {
    while (u != NIL && key != u->key) {
        if (key < u->key) { u = u->left; }
        else { u = u->right; }
    }
    return u;
}

Node *treeMinimum(Node *u) {
    while (u->left != NIL) {
        u = u->left;
    }
    return u;
}

Node *treeSuccessor(Node *u) {
    if (u->right != NIL) {
        return treeMinimum(u->right);
    } else {
        Node *successor = u->parent;
        while (successor != NIL && u == successor->right) {
            u = successor;
            successor = successor->parent;
        }
        return successor;
    }
}

void treeDelete(Node *u) {
    Node *y;
    Node *x;
    if (u->left == NIL || u->right == NIL) {
        y = u;
    } else {
        y = treeSuccessor(u);
    }

    if (y->left != NIL) {
        x = y->left;
    } else {
        x = y->right;
    }

    if (x != NIL) {
        x->parent = y->parent;
    }

    if (y->parent == NIL) {
        root = x; 
    } else {
        if (y == y->parent->left) {
            y->parent->left = x;
        } else if (y == y->parent->right) {
            y->parent->right = x;
        }

        if (y != u) {
            u->key = y->key;
        }
    }
    free(y);
}

void inorder(Node *u) {
    if (u == NIL) { return; }
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) { return; }
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        string command;
        cin >> command;
        int key;
        if (command == "insert") {
            scanf("%d", &key);
            insert(key);
        } else if (command == "find") {
            scanf("%d", &key);
            if (find(root, key) != NIL) { printf("yes\n"); }
            else { printf("no\n"); }
        } else if (command == "delete") {
            scanf("%d", &key);
            treeDelete(find(root, key));
        } else if (command == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 21916
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;

void main()
{
    string ss;
    foreach(line; stdin.byLine)
        ss ~= line.chomp;

    auto s = ss.toLower;
    foreach(c; iota('a', 'z'+1)){
        auto cc = cast(char)c;
        writefln("%s : %s", cc, s.count(cc));
    }
}

Measured memory_bytes: 1076
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int func(int N) {
  int x = N, sum = 0;
  while(x>0) {
    sum += x%10;
    x/=10;
  }

  return sum;
}

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

  n = func(N);

  if(!(N%n)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000002

long long get(map<int,vector<int>> M0,map<int,vector<int>> M1){
	long long ret = Inf;
	for(auto &a:M1){
		sort(a.second.begin(),a.second.end());
	}
	
	for(auto a:M0){
		auto it = M1.lower_bound(a.first);
		if(it==M1.end())continue;
		if(it->first!=a.first)continue;
		for(int i=0;i<a.second.size();i++){
			auto it2 = upper_bound(it->second.begin(),it->second.end(),a.second[i]);
			if(it2==it->second.end())continue;
			ret = min(ret,(long long)abs(a.second[i] - (*it2)));
		}
	}
	
	return ret*5;
}

long long get2(map<int,vector<int>> M0,map<int,vector<int>> M1){
	long long ret = Inf;
	for(auto &a:M1){
		sort(a.second.begin(),a.second.end());
	}
	
	
	for(auto a:M0){

		auto it = M1.lower_bound(a.first);
		if(it==M1.end())continue;
		if(it->first!=a.first)continue;
		for(int i=0;i<a.second.size();i++){
			auto it2 = upper_bound(it->second.begin(),it->second.end(),a.second[i]);
			//if(a.first==40)cout<<a.second[i]<<endl;
			if(it2==it->second.end())continue;
			ret = min(ret,(long long)abs(a.second[i] - (*it2)));
		}
	}
	
	return ret*10;
}

long long solve(int N,vector<int> X,vector<int> Y,vector<int> U){
	
	vector<map<int,vector<int>>> M(4),M2(8);
	
	for(int i=0;i<N;i++){
		if(U[i]%2==0)M[U[i]][Y[i]].push_back(X[i]);
		else M[U[i]][X[i]].push_back(Y[i]);

		if(U[i]==0){
			M2[0][X[i]-Y[i]].push_back(-X[i]);
			M2[6][X[i]+Y[i]].push_back(-X[i]);
		}
		if(U[i]==1){
			M2[3][X[i]-Y[i]].push_back(X[i]);
			M2[7][X[i]+Y[i]].push_back(-X[i]);
		}
		if(U[i]==2){
			M2[2][X[i]-Y[i]].push_back(X[i]);
			M2[4][X[i]+Y[i]].push_back(X[i]);
		}
		if(U[i]==3){
			M2[1][X[i]-Y[i]].push_back(-X[i]);
			M2[5][X[i]+Y[i]].push_back(X[i]);
		}
	}
	
	long long ans = Inf;
	
	ans = min(ans,get(M[0],M[2]));
	ans = min(ans,get(M[1],M[3]));
	
	for(int i=0;i<8;i+=2){
		ans = min(ans,get2(M2[i+1],M2[i]));
	}
	
	return ans;
}
	
	/*
long long solve2(int N,vector<int> X,vector<int> Y,vector<int> U){
	long long ret =Inf;
	
	for(int i=0;i<N;i++){
		X[i]*=10;
		Y[i]*=10;
	}
	
	for(int _=0;_<100000;_++){
		for(int i=0;i<N;i++){
			if(U[i]==0)X[i]++;
			if(U[i]==1)Y[i]++;
			if(U[i]==2)X[i]--;
			if(U[i]==3)Y[i]--;
		}
		
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				if(X[i]==X[j]&&Y[i]==Y[j]){

					return _+1;
				}
			}
		}
		
		
	}
	
	return Inf;
}
	

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


	int N;
	cin>>N;

	vector<int> X(N),Y(N);
	vector<int> U(N);
	set<pair<int,int>> S;
	for(int i=0;i<N;i++){
		char c;
		
		
		scanf("%d %d %c",&X[i],&Y[i],&c);

		if(c=='R')U[i]=0;
		if(c=='U')U[i]=1;
		if(c=='L')U[i]=2;
		if(c=='D')U[i]=3;
		
	}
	
	long long ans = solve(N,X,Y,U);
	if(ans >= 1000000000)cout<<"SAFE"<<endl;
	else cout<<ans<<endl;
	//cout<<ans<<','<<solve2(N,X,Y,U)<<endl;

	return 0;
}

Measured memory_bytes: 94664
N = int(input())
A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0

for i in range(N):
    ans += B[A[i]]
    if i != 0 and A[i] == A[i - 1] + 1:
        ans += C[A[i - 1]]

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const ll NEUT = -1e18, MAXN = 2e5+10;
ll tree[4*MAXN], lazy[4*MAXN], dp[MAXN];

ll op(ll a, ll b){
  return max(a,b);
}

void unlazy(int node, int start, int end){
  tree[node] += lazy[node];
  if(start != end){
    lazy[2*node] += lazy[node];
    lazy[2*node+1] += lazy[node];
  }
  lazy[node] = 0;
}

void update(int l, int r, ll val, int node = 1, int start = 1, int end = MAXN){
  if(lazy[node]) unlazy(node, start, end);
  if(start > end || start > r || end < l) return;
  if(l <= start && end <= r){
    tree[node] += val;
    if(start != end) lazy[2*node] += val, lazy[2*node+1] += val;
    return;
  }
  int mid = (start + end) / 2;
  update(l, r, val, 2*node, start, mid);
  update(l, r, val, 2*node + 1, mid + 1, end);
  tree[node] = op(tree[2*node], tree[2*node+1]);
}

ll query(int l, int r, int node = 1, int start = 1, int end = MAXN){
  if(start > end || start > r || end < l) return NEUT;
  if(lazy[node]) unlazy(node, start, end);
  if(l <= start && end <= r) return tree[node];
  int mid = (start + end) / 2;
  return op(query(l, r, 2*node, start, mid), query(l, r, 2*node + 1, mid + 1, end));
}

vector<ii> g[MAXN];

int main(){FIN;
  int n,m,l,r,v; cin >> n >>m;
  fore(i,0,m) cin >> l >> r >> v, g[l].pb({r,v});
  for(int i = n; i >= 0; i--){
    dp[i] = query(i+1,n+1);
    update(i+1,i+1,dp[i]);
    for(auto x : g[i]) update(i+1, x.fst+1, x.snd);
  }
  cout << dp[0] << endl;
}

Measured memory_bytes: 23936
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define TRUE 1
#define FALSE 0

void initialize();
void printBoard();
void recuresive(int);

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];

bool X[N][N];

void initialize(){
  int i;
  for(i = 0; i < N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i = 0; i < 2 * N - 1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(){
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(X[i][j]) if(row[i] != j) return;
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recuresive(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }
  for(j = 0; j < N; j++){
    if(NOT_FREE == col[j] || NOT_FREE == dpos[i + j] || NOT_FREE == dneg[i - j + N - 1]) continue;
    row[i] = j;
    col[j] = NOT_FREE;
    dpos[i + j] = NOT_FREE;
    dneg[i - j + N - 1] = NOT_FREE;
    recuresive(i + 1);
    row[i] = FREE;
    col[j] = FREE;
    dpos[i + j] = FREE;
    dneg[i - j + N - 1] = FREE;
  }
}

int main(){
  int i, j, k, r, c;
  initialize();
  for(i = 0; i < N; i++) for(j = 0; j < N; j++) X[i][j] = false;
  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }
  recuresive(0);
  
  return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = 0;
    int now = -2;
    rep(i,n) {
        ans += b[a[i]];
        if(a[i] == now+1) ans += c[now];
        now = a[i];
    }
    cout << ans << endl;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using pint = pair<int, int>;
using pstring = pair<int, string>;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> score(N+2,1);
    for(ll i = 1; i<N+1; i++) cin >> score.at(i);
    // 最初のK番目の点数を計算
    for( ll i = K+1; i <= N; i++) {
        if( score.at(i-K) < score.at(i) ) { cout << "Yes" << endl; }
        else { cout << "No" << endl; }
    }

    return 0;
}


Measured memory_bytes: 4784
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct q {
    long l;
    long r;
}q_t;

int main()
{
    long n = 0;
    long qnum = 0;

    if(scanf("%ld %ld", &n, &qnum) != 2){
        return 0;
    }

    char* s = (char*)calloc(n, sizeof(char));
    if(scanf("%s", s) != 1){
        return 0;
    }

    q_t* qs = (q_t*)calloc(qnum, sizeof(q_t)); 
    for(long i = 0 ; i < qnum ; i++){
        if(scanf("%ld %ld", &(qs[i].l), &(qs[i].r)) != 2){
            return 0;
        }
    }

    long count = 0;
    long* ac_count = (long*)calloc(n, sizeof(long));
    for(long i = 0; i < n ; i++){
        if(i == 0){
            ac_count[i] = 0;
            continue;
        }
        if((s[i] == 'C') && (s[i-1] == 'A')){
            count++;
        }
        ac_count[i] = count;
    }  

    for(long i = 0 ; i < qnum ; i++){
        long ac_num = ac_count[qs[i].r - 1] - ac_count[qs[i].l - 1];
        printf("%ld\n", ac_num);
    }

    free(s);
    free(qs);
    free(ac_count);
    return 0;
}

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

money = 1000
kabu = 0

for i in range(0, len(a)-1):
  if a[i] > a[i+1]:
    money += kabu*a[i]
    kabu = 0
  else:
    kabu += money//a[i]
    money %= a[i]
    
money += kabu*a[-1]
print(money)


Measured memory_bytes: 9176
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in int read()
	{
		int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=5e5+5,p=998244353;
int n,m,mx,mn,ans,cm[N],cn[N],fac[N],inv[N];
in void M(int &x) {x-=p;x+=x>>31&p;}
in int qpow(int a,int b) {int c=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)c=1ll*a*c%p;return c;}
in int c(int n,int m) {return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;}
int main()
{
	n=read(),m=read();mx=max(n,m);mn=min(n,m);
	fac[0]=cm[0]=cn[0]=1;for(int i=1;i<=mx;i++) fac[i]=1ll*fac[i-1]*i%p;
	inv[mx]=qpow(fac[mx],p-2);for(int i=mx-1;~i;i--) inv[i]=inv[i+1]*(i+1ll)%p;
	for(int i=1;i<=n;i++) cm[i]=cm[i-1]*(m+1ll)%p;
	for(int i=1;i<=m;i++) cn[i]=cn[i-1]*(n+1ll)%p;
	for(int i=0;i<=mn;i++)
	{
		int res=1ll*c(n,i)*c(m,i)%p*fac[i]%p*cm[n-i]%p*cn[m-i]%p;
		M(ans+=(i&1)?p-res:res);
	}
	write(ans,'\n');
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 11440
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main(){
	stack<int> S;
	string buf;
	while (cin >> buf){
		if (buf == "+") {
			int b = S.top();
			S.pop();
			int a = S.top();
			S.pop();
			S.push(a + b);
		}
		else if (buf == "-") {
			int b = S.top();
			S.pop();
			int a = S.top();
			S.pop();
			S.push(a - b);
		}
		else if (buf == "*") {
			int b = S.top();
			S.pop();
			int a = S.top();
			S.pop();
			S.push(a * b);
		}
		else {
			S.push(stoi(buf));
		}
	}
	cout << S.top() << endl;
}

Measured memory_bytes: 1204
N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)
ans = A[0]
A = A[1:]
ans += 2 * sum(A[:(N-2)//2])
if N % 2 == 1:
  ans += A[(N-2)//2]
print(ans)

Measured memory_bytes: 31444
#include<bits/stdc++.h>
#include<cstdio>
#define ll long long int
#define pb push_back
using namespace std;
int main()
{
    ll n,i,j=-1,k,x,y,sum=0;

    cin>>n;
    ll a[n+5];
    ll b[n+5];
    for(i=2;i<=n;i++)
    {
        cin>>b[i];
    }
    a[1]=b[2];
    sum+=a[1];
    for(i=2;i<=n;i++)
    {
        a[i]=b[i];
        sum+=a[i];
        k=max(a[i],a[i-1]);
        if(k>b[i])
        {
            sum-=a[i-1];
            a[i-1]=b[i];
            sum+=b[i];
        }
    }
   cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define PB push_back
#define in scanf
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
int dis,temp,k,n,N;
void solve(){
cin >> N;
REP(l,N){
	cin >>n >> k; 
	vector <int> a ;
	if(n!=0 ){
	REP(i,n){
		cin >> temp;
		a.push_back(temp);
	}
	dis = a[a.size()-1]-a[0];
	vector <int> d ;
	REP(i,a.size()-1){
		d.push_back(a[i+1]-a[i]);
	}
	sort(d.begin(),d.end(),greater<int>());
	 if(k>=1 && n>k)REP(i,k-1)dis-=d[i];
	 else if(n<=k)dis = 0;
	
	cout << dis <<endl;
	}else {
		cout << 0 <<endl;
	}


}
}




	
int main(){
	solve();

}

Measured memory_bytes: 2392
n = int(input())
h = [int(i) for i in input().split()]
flag = False
for i in range(n-1):
  sa = h[i] - h[i+1]
  
  if sa > 1:
    print("No")
    exit()
   
  if sa == True and flag:
    print("No")
    exit()
  
  if sa == 1:
    flag = True
    
  if sa < 0:
    flag = False

print("Yes")

Measured memory_bytes: 14396
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;
int main (){
    int N,K,R,S,P;
    cin >> N >> K;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    int ans =0 ;
    char te[N] = {-1}; 

    for(int i=0;i<K;i++){
        if(T[i]=='r'){
            ans += P;
            te[i] = 'p'; 
        }
        else if(T[i]=='s'){
            ans += R;
            te[i] = 'r'; 
        }
        else if(T[i]=='p'){
            ans += S;
            te[i] = 's'; 
        }
        

    }

    for(int i=K;i<N;i++){
        
            if(T[i]=='r'&& te[i-K] != 'p'){
                ans += P;
                te[i] = 'p'; 
            }
            else if(T[i]=='s'&& te[i-K] != 'r'){
                ans += R;
                te[i] = 'r'; 
            }
            else if(T[i]=='p'&& te[i-K] != 's'){
                ans += S;
                te[i] = 's'; 
            }


    }

    cout << ans;


}



Measured memory_bytes: 512
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;

ll mod=998244353;
#define P pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
P op(P a,P b){
    return P{(a.first+b.first)%mod,(a.second+b.second)%mod};
}
P e(){return{0,0};}
P mapping(ll f,P x){
    if(f==0)return x;
    return P{x.first,f*x.first%mod};
}
ll composition(ll f,ll g){
    return (f?f:g);
}
ll id(){return 0;}
int n,q;
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>q;
    lazy_segtree<P,op,e,ll,mapping,composition,id>seg(n);
    ll p=1;
    for(int i=n-1;i>=0;i--){
        seg.set(i,P{p,p});
        p=p*10%mod;
    }
    rep(i,q){
        int l,r,d;
        cin>>l>>r>>d;
        l--,r--;
        seg.apply(l,r+1,d);
        cout<<(seg.all_prod().second)<<endl;
    }
    return 0;
}


Measured memory_bytes: 16668
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#define INF 100000001
using namespace std;
typedef long long ll;
int a[4];
int ans = 3000;
void cost(int x, int y, int z) {
	int w = abs(a[y] - a[x]) + abs(a[z] - a[y]);
	if (w < ans) {
		ans = w;
	}
	
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	cost(0, 1, 2);
	cost(0, 2, 1);
	cost(1, 0, 2);
	cost(1, 2, 0);
	cost(2, 1, 0);
	cost(2, 0, 1);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int i,m,h,x,sum,len,cot;
	char S[201];
	while(1){
		sum = 0;
		cot = 0;
		scanf("%s",S);
		if(strcmp(S,"-") == 0) break;
		scanf("%d",&m);
		for(i=0;i<m;i++){
			scanf("%d",&h);
			sum += h;
		}
		len = strlen(S);
		x = sum % len;
		for(i=x;cot<len;i++){
			cot++;
			printf("%c",S[i]);
			if(cot == len) break;
			if(len-1 == i) i = -1;
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 568
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
	char a[100];
	scanf("%s",a);
	if(a[0]!=a[strlen(a)-1])
	 printf("No\n");
	 else
	 printf("Yes\n");  
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> A(N),B(N); rep(i,N) cin>>A[i]>>B[i];
  
  vector<tuple<ll,ll,ll>> vec(N); rep(i,N) vec[i]={A[i]+B[i],A[i],B[i]};
  sort(vec.rbegin(),vec.rend());
  
  ll a=0,b=0;
  rep(i,N){
    ll sum_i,A_i,B_i; tie(sum_i,A_i,B_i)=vec[i];
    if(i%2==0) a+=A_i;
    else b+=B_i;
  }
  
  cout<<a-b<<endl;
  
  return 0;
}

Measured memory_bytes: 7164
#include <iostream>
using namespace std;
int main(){
    string Weather[3]={"Sunny","Cloudy","Rainy"};
    string S;
    cin>>S;
    for(int i=0;i<3;i++){
        if(S==Weather[i] && i!=2){
            cout<<Weather[i+1]<<endl;
        }else if(S==Weather[i]){
            cout<<Weather[0]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
//#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
//const int inf = 1e18;  
const int mod1 = 998244353;
const int mod = 1e9 + 7;
const int nax = 200005;
int n,k,dp[nax],pref[nax],interval[11][2];
void solve()
 {
   cin>>n>>k;
   loop(i,0,k)
    cin>>interval[i][0]>>interval[i][1];
   pref[1] = 1,dp[1] = 1;
   pref[0] = 0;
   loop(i,2,n+1)
   {
    dp[i] = 0;
    pref[i] = pref[i-1];
    loop(j,0,k)
     if(i >= interval[j][0])
       {
        int short_jump = interval[j][0];
        int long_jump = min(interval[j][1],i);
        int l = max(1,i - long_jump);
        int r = i - short_jump;
        dp[i] += (pref[r] - pref[l-1] + mod1)%mod1;
        dp[i] %= mod1;
       }
    pref[i] += dp[i];
    pref[i] %= mod1;
   }
  cout<<dp[n];
 }
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);  
  /*int t;
  cin>>t;
  while(t--)*/
  solve();
  // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 


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

using namespace std;

const int maxn = 710;
const int oo = 1e9;

int n,m,ed[maxn][maxn],c[3],vis[maxn],f[maxn],lab[maxn];

void visit(int u,int col) {
    vis[u]=1;
    c[col]++;
    lab[u]=col;
    for (int v=1;v<=n;v++) if (v!=u) {
        if (ed[u][v]) continue;
        if (vis[v] && lab[v]==lab[u]) {
            cout<<-1<<endl;
            exit(0);
        }
        if (!vis[v]) visit(v,col^1);
    }
}

int main() {
  //  freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        int a,b;
        cin>>a>>b;
        ed[a][b] = ed[b][a] = 1;
    }
    f[0]=1;
    for (int i=1;i<=n;i++)
        if (!vis[i]) {
            c[0] = c[1] = 0;
            visit(i,0);
            for (int j=n;j>=0;j--) {
                int tmp=0;
                if (j>=c[0]) tmp |= f[j-c[0]];
                if (j>=c[1]) tmp |= f[j-c[1]];
                f[j] = tmp;
            }
        }
    int ans = oo;
    for (int i=0;i<=n;i++)
        if (f[i]) ans = min(ans,i*(i-1)/2 + (n-i)*(n-i-1)/2);
    cout<<ans;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s;
  
  cin >> s;
  
  if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
function Main(file) {
  const input = file.split("\n");
  const line_1 = input[0].split(' ');
  const X = parseInt(line_1[0]);
  const A = parseInt(line_1[1]);
  if (X < A) return console.log(0);
  console.log(10);
}

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
    #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #include <algorithm>
    #include <bits/stdc++.h>
    #define MOD 1000000007
    #define ll long long
    #define mm(arr) memset(arr, 1, sizeof(arr))
    #define scanArray(a,n) for(ll i = 0; i < n; i++){cin >> a[i];}
    using namespace std;
    int main(){
        FAST
        ll a,b; cin >> a >> b;
        cout << a*b << endl;
     
        return 0;
    }

Measured memory_bytes: 3684
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let ss = (read string).ToCharArray()
    Array.countBy id ss
    |> Array.map snd
    |> fun xs ->
        if Array.length xs = 1
        then 0
        else Array.min xs
    |> fun x -> printfn "%i" (x * 2)
    0

Measured memory_bytes: 15452
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0 || (a+b)%3==0){
        cout<<"Possible"<<endl;
    }
    else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100006];
int main()
{   int n;
   int x;
     cin>>n;
     for(int i=0;i<n;i++)
            cin>>a[i];

     sort(a,a+n);
     ll sum=a[0];
       ll maxs=sum;
      for(int i=1;i<n;i++)
      {
           if(maxs==1)
          {
              break;
          }
          sum=a[i]%sum;
          if(sum==1)
          {
              maxs=1;
              break;
          }
         else  if(sum==0)
            sum=maxs;
          else
          {

              maxs=__gcd(maxs,sum);
              sum=maxs;

          }


      }
      cout<<maxs<<endl;


return 0;
}


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

using namespace std;

int a[1000000];

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

    int n,k;
    cin>>n>>k;

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

    int c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=k)
        {
            c++;
        }
    }

    cout<<c<<endl;

    return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi a(n+1,0);
	FOR(i,1,n+1)
		a[i]=a[i-1]+read();
	int p=0,r=0,ans=inf;
	REP(q,n+1){
		while(p<q&&a[p]<a[q]-a[p])
			p++;
		while(r<n&&a[r]-a[q]<a[n]-a[r])
			r++;
		REP(i,2)REP(j,2){
			int s=p-i,t=r-j;
			if(0<=s&&q<=t){
				int b=a[s];
				int c=a[q]-a[s];
				int d=a[t]-a[q];
				int e=a[n]-a[t];
				chmin(ans,max({b,c,d,e})-min({b,c,d,e}));
			}
		}
	}
	print(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    int X,Y; SCD2(X,Y);
    PRINTD(X+(Y/2));
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101

int G[MAX][MAX];

int main(){
  int n,i,j,k,u;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      int v;
      scanf("%d",&v);
      G[u][v]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=n)printf("%d ",G[i][j]);
      else printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

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

string q; int N,cnt[30];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> q;
    N = q.length();
    ll res=1LL*N*(N+1)/2;

    int i;
    for (i=0; i<N; i++)
        cnt[q[i]-'a']++;

    for (i=0; i<26; i++)
        res-=1LL*cnt[i]*(cnt[i]+1)/2;
    cout << res+1 << "\n";
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  vector<vector<int>> G(N);
  vector<pair<int,int>> vp;
  for(int i=1;i<N;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }
 
  int K=0;
  map<pair<int,int>,int> I;
  vector<int> cs(N,0); // color of edge between its parent
 
  vector<int> used(N,0);
  queue<int> que;
  used[0]=1;
  que.emplace(0);
  while(!que.empty()){
    int v=que.front();que.pop();
    if(K<(int)G[v].size()) K=G[v].size();
    int cur=1;
    for(int u:G[v]){
      if(used[u]) continue;
      if(cur==cs[v]) cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      que.emplace(u);
    }
  }
 
  cout<<K<<endl;
  for(auto p:vp) cout<<I[p]<<endl;
  return 0;
}

Measured memory_bytes: 20084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin a(n),b(n+1),c(n+1);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    b[n]=inf;c[n]=inf;
    sort(all(b));
    sort(all(c));
    map<int,int> numb;numb[b[0]]=n;
    map<int,int> numc;numc[c[0]]=n;
    rep2(i,1,n)if(b[i]!=b[i-1])numb[b[i]]=n-i;
    rep2(i,1,n)if(c[i]!=c[i-1])numc[c[i]]=n-i;
    map<int,ll> btoc;
    ll tmp=0;
    for(int i=n-1;i>=0;i--){
        btoc[b[i]]=tmp+(ll)numc[*upper_bound(all(c),b[i])];
        tmp=btoc[b[i]];
    }
    ll sum=0;
    rep(i,n)sum+=btoc[*upper_bound(all(b),a[i])];
    cout<<sum<<endl;
}

Measured memory_bytes: 17024
from heapq import heappush, heappop
class MinCostFlow:
    INF = 10**18

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap, cost):
        forward = [to, cap, cost, None]
        backward = forward[3] = [fr, 0, -cost, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def flow(self, s, t, f):
        N = self.N; G = self.G
        INF = MinCostFlow.INF

        res = 0
        H = [0]*N
        prv_v = [0]*N
        prv_e = [None]*N

        d0 = [INF]*N
        dist = [INF]*N

        while f:
            dist[:] = d0
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                r0 = dist[v] + H[v]
                for e in G[v]:
                    w, cap, cost, _ = e
                    if cap > 0 and r0 + cost - H[w] < dist[w]:
                        dist[w] = r = r0 + cost - H[w]
                        prv_v[w] = v; prv_e[w] = e
                        heappush(que, (r, w))
            if dist[t] == INF:
                return None

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, prv_e[v][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = prv_e[v]
                e[1] -= d
                e[3][1] += d
                v = prv_v[v]
        return res

N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

G = MinCostFlow(2*N+3)
G.add_edge(0,2*N+2,10**18,0)
G.add_edge(2*N+2,2*N+1,10**18,0)

for i in range(N):
    G.add_edge(0,i+1,K,0)
    for j in range(N):
        G.add_edge(i+1,N+1+j,1,-A[i][j])

for j in range(N):
    G.add_edge(N+1+j,2*N+1,K,0)

f = G.flow(0,2*N+1,N**2)
print(-f)

res = [["." for j in range(N)] for i in range(N)]
for i in range(N):
    for w, cap, _, _ in G.G[i+1]:
        if N+1<=w<=2*N:
            j = w - (N+1)
            if cap==0:
                res[i][j] = "X"
for i in range(N):
    print("".join(res[i]))


Measured memory_bytes: 73308
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define print(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;

int n,adj[61][50][50],ans[50][50];

int sum()
{
	int sum = 0;
	loop(i,0,n) loop(j,0,n) sum = (sum + ans[i][j])%mod;
	return sum;
}

void product(int a[][50],int b[][50],int res[][50])
{
	int temp[n][n];
	init(temp,0);
	loop(i,0,n)
		loop(j,0,n)
			loop(k,0,n) temp[i][j] = (temp[i][j] + a[i][k]*b[k][j])%mod;
	loop(i,0,n) loop(j,0,n) res[i][j] = temp[i][j];
}


signed main()
{
	fastio(0);
	int k;
	cin>>n>>k;
	loop(i,0,n) ans[i][i] = 1;
	loop(i,0,n) loop(j,0,n) cin>>adj[0][i][j];
	loop(i,1,61) product(adj[i-1],adj[i-1],adj[i]);
	loop(i,0,61)
	{
		if((k>>i)==0) break;
		if((k>>i) & 1)  product(adj[i],ans,ans);
	}
	cout<<sum()<<endl;
	return 0;		
}

Measured memory_bytes: 1536
import java.io.PrintStream;
    import java.util.Scanner;
	
	public class Main {
        private static final PrintStream so = System.out;
        private static final Scanner     sc = new Scanner(System.in);
    
        public static void main(String[] args) {
            int n = sc.nextInt();
            int g = sc.nextInt();
            
            int[] p = new int[n + 1];
            int[] comp = new int[n + 1];
            int[] maxUnComp = new int[n + 1];
            
            for (int i = 1; i <= n; i++) {
                p[i] = sc.nextInt();
                maxUnComp[i] = 100*(i) * (p[i] - 1);
                comp[i] = maxUnComp[i] + 100*i + sc.nextInt();
            }
            
            int ans = Integer.MAX_VALUE;
            for (int pattern = 0; pattern < 1 << n; pattern++) {
                int sumS = sum(comp, pattern, n); // score
                int needed = g - sumS;
                int idx = firstIdxOf0(pattern, n) + 1;
                
                if (needed > maxUnComp[idx]) continue;
                int sumQ = sum(p   , pattern, n); // number of questions to solve
                sumQ += idx == 0 ? 0 : Math.max(ceil(needed, 100*idx), 0);
                ans = Math.min(ans, sumQ);
            }
            so.println(ans);
        }
        
        // ^q^
        static int ceil(int a, int b) {
            return (a + b - 1) / b;
        }
        
        static int sum(int[] a,int bits, int numBits) {
            int sum = 0;
            int mask = 1;
            for (int i = 0; i < numBits; i++) 
                if ((bits >> i & mask) == 1)
                    sum += a[i+1];
            return sum;
        }
        
        static int firstIdxOf0(int bits, int numBits) {
            int mask = 1;
            for (int i = numBits - 1; i >= 0; i--)
                if ((bits >> i & mask) == 0)
                    return i;
            return -1;
        }
    }


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,a[maxn],b[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cout << fixed << setprecision(12);
	cin >> n;
	rep(n) cin >> a[i];
	rep(n) b[i]=a[i];
	sort(b,b+n);
	rep(n) print1(a[i]==b[n-1]?b[n-2]:b[n-1]);
	return 0;
}

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

int main(){
  int X;
  cin>>X;
  
  int ans1,ans2;
  ans1=ans2=0;
  
  
  for(int i=-120;i<121;i++){
    for(int j=-120;j<121;j++){
      long long int ans;
      ans=pow(i,5)-pow(j,5);
      
      if(ans==X){
        ans1=i;
        ans2=j;
        break;
      }
    }
      
    
  }
  
  
  cout<<ans1<<" "<<ans2<<endl;
  


}

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

int main(){
  int h,w;
  cin >> h >> w;

  int mas[510][510];
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> mas[i][j];
    }
  }

  queue<int> que[4];
  int cnt = 0;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(mas[i][j]%2 != 0){
        if(j != w-1){
          cnt++;
          que[0].push(i+1);
          que[1].push(j+1);
          que[2].push(i+1);
          que[3].push(j+2);
          mas[i][j+1]++;
          mas[i][j]--;
        }else if(i != h-1){
          cnt++;
          que[0].push(i+1);
          que[1].push(j+1);
          que[2].push(i+2);
          que[3].push(j+1);
          mas[i+1][j]++;
          mas[i][j]--;
        }
      }
    }
  }

  cout << cnt << endl;
  for(int i = 0;i < cnt;i++){
    cout << que[0].front() <<  " " << que[1].front() << " " << que[2].front() << " "<< que[3].front() << endl;
    for(int i = 0;i < 4;i++) que[i].pop();
  }
  return 0;
}



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

using namespace std;

int num_track(const vector<int>& packets,const int max_load){
    int counter = 1;
    int individual_load = 0;
    for(int i = 0;i < packets.size();i++){
        individual_load += packets[i];
        if(individual_load > max_load){
            counter++;
            individual_load = packets[i];
        }
    }
    return counter;
}


int main(){
    int n,k;
    int sum = 0,temp;
    int counter = 0, individual_load = 0;
    int right,left = 0,mid;
    int tracks;

    scanf("%d %d",&n,&k);
    vector<int> packet_array(n,0);

    for(int i = 0; i < n;i++){
        scanf("%d",&temp);
        packet_array[i] = temp;
        sum += temp;
        left = max(left,temp);
    }
    right = sum;
    while(left < right){
        mid   = (left + right)/2;
        tracks = num_track(packet_array,mid);
        if(tracks > k) left = mid+1;
        if(tracks <= k) right=mid; 
    }
    
    printf("%d\n",left);
    
    

    return 0;   
}



Measured memory_bytes: 3408