akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template<class S,class T>
string to_string(pair<S,T> p){
	return "{"+to_string(p.first)+","+to_string(p.second)+"}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
	ll N,W;
	cin>>N>>W;
	vector<ll> w(N),v(N);
	FOR(i,N)cin>>w[i]>>v[i];
	vector<ll> dp(210000);
	FOR(i,N){
		for(ll j=W;j>=0;--j){
			dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
		}
	}
	print(*max_element(dp.begin(),dp.begin()+W+1));
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int r;
    double pi = 3.141592653589793238;
    cin >> r; 
    cout.precision(19);

    cout << (double)r * 2 * 3.14 << "\n";



}

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

int main()
{
    long long n;
    cin >> n;
    vector<long long> a(n);
    rep(i, n) cin >> a.at(i);

    long long answer = INT_MAX;
    long long x = 0, y = 0;
    rep(i, n) y += a.at(i);
    for (int i = 0; i < n - 1; i++)
    {
        x += a.at(i);
        y -= a.at(i);

        answer = min(answer, abs(x - y));
    }

    cout << answer << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

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

    queue <int> storder;
    queue <int> stdesire[n];
    vector <int> d[m];
    for (int i = 0; i < n; i++) {
      storder.push(i);
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int ID;
        cin >> ID;
        stdesire[i].push(ID);
      }
    }
    int ans = 0;
    while (!storder.empty()) {
      int p = storder.front(); storder.pop();
      int cost = 0;
      int ID = stdesire[p].front(); stdesire[p].pop();
      bool ok = false;
      // ??¬?????¨??£?????????
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < d[i].size(); j++) {
          if (d[i][j] == ID) {
            ok = true;
            cost += i+1;
            d[i].erase(d[i].begin()+j);
            break;
          }
        }
        if (ok) break;
      }
      if (!ok) {
        cost += m+1;
      }

      // ??¬?????????
      bool shelf = true;
      for (int i = 0; i < m; i++) {
        if (d[i].size() < c) {
          if (i == 0) {
            d[i].push_back(ID);
            cost += 1;
          }else {
            cost += (i+1)*2+1; ok = false;
            for (int j = 1; j < m; j++) {
              int bias = j == i;
              if (d[j].size()+bias < c) {
                int t = d[0][0];
                d[0].erase(d[0].begin());
                d[j].push_back(t); cost += 1+j+1;
                ok = true;
                break;
              }
            }
            if (!ok) {
              int t = d[0][0];
              d[0].erase(d[0].begin());
              cost += 1+m+1;
            }
            d[0].push_back(ID);
          }
          shelf = false;
          break;
        }
      }
      if (shelf) {
        cost += (m+1)*2+1+(m+1)+1;
        d[0].erase(d[0].begin());
        d[0].push_back(ID);
      }
      if (stdesire[p].size()) {
        storder.push(p);
      }

      ans += cost;
    }

    cout << ans << endl;
  }
}

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

typedef complex<double> P;
const double EPS = 1e-8;
const P INF = P(-1E8,-1E8);
vector<P> v;
int N;

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
  bool operator > (const P& a, const P& b){
    return fabs(real(a)-real(b)) > EPS ? imag(a) > imag(b) : real(a) > real(b);
  }
}

//  a -> b -> c ?????????????????? b -> c ?????????
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1; //???????¨???????
  if(cross(b,c) < -EPS) return -1; // ????¨???????
  if(dot(b,c) < -EPS) return 2; // c -- a -- b ????????´???
  if(norm(b) < norm(c)) return -2; // a -- b -- c ????????´???
  return 0; // a -- c -- b ????????´????
}

double getAngle(P a,P b){
  return atan2(b.imag()-a.imag(),b.real()-a.real());
}

P getNextP(P a,P b,int *flag){
  double ang = getAngle(a,b);
  if( ang < -EPS ) 2*M_PI + ang;
  int p=-1;
  double pa=0;
  // cout << ang*180.0/M_PI << endl;
  for(int i=0;i<N;i++){
    if( ccw( a, b, v[i] ) == -1 ){
      double na = getAngle(b,v[i]);
      if( na < -EPS ) 2 * M_PI + ang;
      // cout << b << " -> " << v[i] << " "<< na/M_PI*180.0 << endl;
      double x = abs( ang - na );
      double y = abs( ang - pa );
      if( x > M_PI ) x = abs( ang + 2 * M_PI - na );
      if( y > M_PI ) y = abs( ang + 2 * M_PI - pa );
      if( p == -1 || x < y  ){
        pa = na;
        p = i;
      }
    }
  }
  if( flag[p] ) return INF;
  flag[p] = 1;
  return v[p];
}

int main(){
  while( cin >> N && N ){
    int px=0;
    v.clear();
    for(int i=0;i<N;i++){
      double x,y;
      scanf("%lf,%lf",&x,&y);
      v.push_back( P(x,y) );
      //  cout << v[i] << endl;
      if( v[i].real() < v[px].real() ) 
        px = i;
    }

    if(N < 4 ){
      cout << 0 << endl;
    } else {
      P now = v[px];
      P vn = v[px] + P(0,-1.0);
      int flag[111]={};
      flag[px] = 1;
      vn = getNextP(vn,v[px],flag);
      while(INF/10.0 < vn){
        // cout << now << " "<< vn << endl;
        P nex = getNextP(now,vn,flag);
        now = vn; vn = nex;
      }
      int res = 0;
      for(int i=0;i<N;i++)
        if(!flag[i]) res++;      
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 1344
def main():
	N = int(input())
	A1 = list(map(int, input().split()))
	A2 = list(map(int, input().split()))
	ans = 0
	for i in range(N):
		cur = sum(A1[:i+1])+sum(A2[i:])
		ans = max(ans, cur)
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1e9 + 5
using namespace std;

int solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);

    for (int i = 0; i < n; i++)
        cin >> h[i];

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + k; j++)
        {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
        }
    }
    return dp[n - 1];
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    /*
    int t;
    cin >> t;

    while (t--)
    */
    cout << solve() << "\n";

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;

const int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int dy[8] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  rep(i,10){
    int a = 0;
    bool ok = false;
    for(; a < n-2; a++){
      if(s[a] - '0' == i) {
        ok = true;
        break;
      }
    }
    if(!ok) continue;
    rep(j,10){
      int b = a+1;
      ok = false;
      for(; b < n-1; b++){
        if(s[b] - '0' == j) {
          ok = true;
          break;
        }
      }
      if(!ok) continue;
      rep(k,10){
        int c = b+1;
        ok = false;
        for(; c < n; c++){
          if(s[c] - '0' == k) {
            ok = true;
            break;
          }
        }
        if(ok) ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#define EPS (1e-7)
using namespace std;


long long lcm(long long n, long long m) {
	long long r,x,tmp;
	x = m * n;
	/* 自然数 a > b を確認・入替 */
	if (n < m) {
		tmp = n;
		n = m;
		m = tmp;
	}

	/* ユークリッドの互除法 */
	r = n % m;
	while (r != 0) {
		n = m;
		m = r;
		r = n % m;
	}
	return x / m;

}



int main() {

	int N;
	cin >> N;
	vector < pair<int, pair<int, int>>> desires;
	desires.reserve(N);
	pair<int, int> current_coord = make_pair(0,0);
	int ctime = 0;
	int t1, t2, t3;
	string ans = "Yes";
	for (auto i = 0; i < N; i++)
	{
		cin >> t1 >> t2 >> t3;

		desires.emplace_back(t1, make_pair(t2, t3));
	}

	for (auto i = 0; i < N; i++)
	{
		int next, time;
		next = abs(desires[i].second.first - current_coord.first) + abs(desires[i].second.second - current_coord.second);
		time = desires[i].first - ctime;
		if (time < next) {
			ans = "No";
			break;
		}
		else {
			if ((time - next) % 2 != 0) {
				ans = "No";
				break;
			}
			else {
				ctime = desires[i].first;
				current_coord = desires[i].second;
			}
		}

	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
int main(void){
    int K,N;
    cin >> K >> N;
    vector<int> A(N), B(N);
    
    for (int i=0; i < N; i++){
        cin >> A.at(i);
    }
    
    int ans = 0;
    int max_diff = 0;
    for (int i=0; i < N; i++){
        int diff;
        
        if (i==N-1){
            diff = (K-A.at(i)) + A.at(0);
            max_diff = max(diff, max_diff);
            ans += diff;
            break;
        }
        
        diff = A.at(i+1) - A.at(i);
        max_diff = max(diff, max_diff);
        ans += diff;
    }
    
    ans -= max_diff;

    cout << ans;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NM = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];
            Console.WriteLine((1900 * M + 100 * (N - M)) * (1 << M));
        }
    }
}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

class Combination{
    private:
        vector<long long> fac, finv, inv;
    
    public:
        Combination(){
            fac = finv = inv = vector<long long> (2 * MAX);

            fac[0] = fac[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for (int i = 2; i < 2 * 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 getCom(int n, int k){
            if (n < k) return 0;
            if (n < 0 || k < 0) return 0;
            return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
        }
};

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

    int N = H - A;

    Combination com = Combination();
    vector<ll> array(N);
    rep(i, N) array[i] = com.getCom(i + B, i);

    ll ans = 0;
    rep(i, N) {
        int y = H - 1 - i, x = W - 1 - B;
        ll c = com.getCom(x + y, x);
        ll pre = i == 0 ? 1 : array[i] - array[i - 1];
        pre %= MOD;
        if (pre < 0) pre += MOD;
        ans += c * pre % MOD;
        ans %= MOD;
        if (ans < 0) ans += MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
int prime(int x){
  int i;
  if(x < 2) return 0;
  if(x == 2) return 1;
  if(x % 2 == 0) return 0;
  for(i = 3;i * i <= x;i += 2)
    if(x % i == 0) return 0;

  return 1;
}

int main(){
  int   n, c = 0, a;
  scanf("%d", &n);
  while(n--){
    scanf("%d", &a);
    c += prime(a);
  }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 596
s = input()

if s.count("R") == 0:
    print(0)
elif s.count("R") == 1:
    print(1)
elif s.count("R") == 3:
    print(3)
else:
    if s == "RRS" or s == "SRR":
        print(2)
    else:
        print(1)

Measured memory_bytes: 9112
L=list(input())
L=list(map(int,L))
dp=[2,1]
MOD=10**9+7
for j in range(1,len(L)):
    a,b=dp
    if L[j]==1:
        dp[0]=(a*2)%MOD
        dp[1]=(a+b*3)%MOD
    elif L[j]==0:
        dp[1]=(b*3)%MOD
print(sum(dp)%MOD)

Measured memory_bytes: 4652
#include <stdio.h>

void sort(int *card)
{
	int i, j, temp;
	
	for (i = 0;i < 5;i++) {
		for (j = 0;j < 4-i; j++) {
			if (card[j] > card[j+1]) {
				temp = card[j];
				card[j] = card[j+1];
				card[j+1] = temp;
			}
		}
	}
}

void check_equal(int *card, int *continuation) /** (n < 5) **/
{
	int count, i, j, std;
	
	for (j=0; j<5; j+=count) {
		count = 0;
		for (i=j; i<5; i++) {
			std = card[j];
			if (std == card[i+1]) count++;
			else break;
		}
		continuation[j] = count;  
		count++; //àµcountª0ÅàjÉ1ÍÁZ³¹é
	}
	
	for (i=0; i<5; i++) {
			if (continuation[i] < 0) continuation[i] = continuation[i-1];
	}
}

int sum(int *array, int n)
{
	int i, add = 0;
	
	for (i=0; i<n; i++) {
		add+= array[i];
	}
	
	return add;
}

int straight(int *card, int n)
{
	int add = 0, i;
	
	for (i=n-1; i>0; i--) {
		if (card[i] == 10 && card[i-1] == 1 && add == 3) return 1;
		add += card[i] - card[i-1];
	}
	
	if (add == 4) return 1;
	else		  return 0;
}

int main(void) {
	int card[5];
	
	while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF) {
		int hash = 0, continuation[5] = {-1, -1, -1, -1, -1};
		char *comp = "null";
		
		sort(card);
		check_equal(card, continuation);
		hash = sum(continuation, 5);
		
		switch (hash) {
			case  2 : comp = "one pair"; break;
			case  4 : comp = "two pair"; break;
			case  6 : comp = "three card"; break;
			case  8 : comp = "full house"; break;
			case 12 : comp = "four card"; break;
			default : if(straight(card, 5)) comp = "straight";
		}
		
		printf("%s\n", comp);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
typedef long long ll;

#define MAX_N 50
using namespace std;
int main(){
    int n;
    int p[MAX_N];
    cin >> n;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(count>2){
            break;
        }
        if((i+1)!=p[i]){
            count++;
        }
    }
    if(count>2){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

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

int main() {
    ll k;

    cin >> k;

    ll total = 0;

    REP(i, k+1){
        REP(j, k+1){
            REP(l, k+1){
                if (i==0 || j==0 || l==0){
                    continue;
                }
                total += gcd(gcd(i, j), l);
            }
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vector<vector<pair<ll, ll>>> G;
vll colors;
ll max_color = 0;

void dfs(ll node, ll color, ll pre) {
    ll new_color = 0;
    if (color == 0) new_color++;

    max_color = max(max_color, (ll)G[node].size());
    for (auto next_node : G[node]) {
        if (next_node.first == pre) continue;
        colors[next_node.second] = new_color;
        dfs(next_node.first, new_color, node);
        new_color++;
        if (new_color == color) new_color++;
    }
}



int main()
{
    ll N; cin >> N;
    G.resize(N);
    colors.resize(N - 1, -1);
    rep(i, N - 1) {
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back({b, i});
        G[b].push_back({a, i});
    }

    dfs(0, -1, -1); // node to proceed, color cannot be used, previous node
    cout << max_color << endl;
    rep(i, N - 1) {
        cout << colors[i] + 1 << endl;
    }
    return 0;
}

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


int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  string str;
  cin >> str;
  if(n % 2 == 0){
    if(str.substr(0, n/2) == str.substr(n/2)){
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else{
    cout << "No" << endl;
    return 0;
  }
}


/*





















*/


Measured memory_bytes: 256
using System;
using System.Linq;

class E
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		long n = h[0], m = h[1];
		var a = read().OrderBy(x => -x).ToArray();

		var s = new long[n + 1];
		for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];

		var a_a = Last(0, 2 * a[0], x =>
		{
			var c = 0L;
			for (int i = 0; i < n; i++)
			{
				var sub = x - a[i];
				c += 1 + Last(-1, n - 1, j => a[j] >= sub);
				if (c >= m) return true;
			}
			return false;
		});

		{
			long r = 0, c = 0;
			for (int i = 0; i < n; i++)
			{
				var sub = a_a - a[i];
				var count = 1 + Last(-1, n - 1, j => a[j] > sub);
				r += s[count] + a[i] * count;
				c += count;
			}
			r += (m - c) * a_a;
			Console.WriteLine(r);
		}
	}

	static long Last(long l, long r, Func<long, bool> f)
	{
		long m;
		while (l < r) if (f(m = r - (r - l - 1) / 2)) l = m; else r = m - 1;
		return l;
	}
}


Measured memory_bytes: 35168
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    
    
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> h[i];
    }
    int m = -1;
    int ret = 0;
    
    for (int i = 0; i < n; ++i)
    {
        if (m <= h[i])
        {
            ret++;
            m = h[i];
        }
    }
    
    cout << ret << endl;
    
    return 0;
}


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

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

  int ans = -1;
  for (int i = 0; i <= 100000; i++) {
    int x = floor(double(i) * 0.08);
    int y = floor(double(i) * 0.10);

    if(x == a && y == b) {
      ans = i;
      break;
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,n) for(ll i=a; i<n; i++)
#define u_m unordered_map
#define u_s unordered_set
#define ff first
#define ss second
#define mp make_pair
using namespace std;
ll __pow(ll x, ll y) {ll res = 1;while(y>0){if(y&1) res*=x; y>>=1; x*=x;}return res;}
ll gcd(ll a , ll b){if(b==0) return a;a%=b;return gcd(b,a);}
bool isprime(ll n){for(ll i=2; i*i<=n; i++){if(n%i==0) return 0;}return 1;}
ll n,m,x,y,z,k;
ll dp(ll n){
    if(n<10) return max((ll)1, n);
    else return max((n%10)*dp(n/10), 9*dp(n/10-1));
}
void solve(){
    cin>>n>>m;
    ll cnt=0;
    fo(i,n){
        cin>>x>>y;
        if(x*x+y*y<=m*m) cnt++;
    }
    cout<<cnt<<endl;
}
int main(){
    ll t=1;
    //cin >> t;
    for(ll i=1; i<=t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3592
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int x, k, d;
    cin >> x >> k >> d;
    chkmax(x, -x);
    if (x / d > k) {
        put(abs(x) - k * d);
        return;
    }
    k -= x / d;
    x %= d;
    put(abs(x - (k % 2) * d));
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 3180
import numpy as np

n, m, c = map(int, input().split())
b = np.array(list(map(int, input().split())))


ans = 0
for i in range(n):
    a = np.array(list(map(int, input().split())))
    if np.dot(a, b) + c > 0:
        ans += 1
    
print(ans)

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,a,b;cin >> n >> a >> b;
    if(!((a ^ b) & 1)){
        cout << (b-a)/2 << endl;
    }else{
        cout << min(a-1,n-b) + 1 + (b-a-1)/2 << endl;
    }
    return 0;
}

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()
{
    vector<int> square;
    rep(i, 16000)
    {
        int s = i * i;
        if (s <= 16000) square.push_back(s);
        else break;
    }

    int n, d;
    cin >> n >> d;

    vector<int> x[n];
    rep(i, n)
    rep(j, d)
    {
        int xx;
        cin >> xx;
        x[i].push_back(xx);
    }

    ll ans = 0;
    rep(i, n)
    for (int j = i + 1; j < n; j++)
    {
        int distance = 0;
        rep(k, d) distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);

        for (auto s: square)
            if (distance == s)
            {
                // cout << i << ' ' << j << ' ' << distance << endl;
                ans++;
                break;
            }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string x,y,a,b,c="",n="",m;
    cin>>x>>y;
    n=y;
    m=x;
    reverse(n.begin(),n.end());
    reverse(m.begin(),m.end());
    if(x==n && m==y)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;



    return 0;
}


Measured memory_bytes: 3536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace panasonic2020
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            double[] hw = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double h = hw[0], w = hw[1];
            if(h == 1 || w == 1)
            {
                Console.WriteLine(1);
                return;
            }
            double ans = Math.Ceiling((h * w) / 2);
            long ans1 = (long)ans;
            Console.WriteLine(ans1);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1010;
char a[55][55];
int n , m;
int f(int x , int y){
    int ans = 0;
    if (x > 0){
        if (a[x-1][y] == '#')  ans ++;
        if (y>0 && a[x-1][y-1]=='#')  ans ++;
        if (y<m-1 && a[x-1][y+1]=='#')  ans ++;
    }
    if (x < n-1){
        if (a[x+1][y] == '#')  ans ++;
        if (y>0 && a[x+1][y-1]=='#')  ans ++;
        if (y<m-1 && a[x+1][y+1]=='#')  ans ++;
    }
    if (y>0 && a[x][y-1]=='#')  ans ++;
    if (y<m-1 && a[x][y+1]=='#')  ans ++;
    return ans;
}
int main()
{
    while (~scanf("%d%d",&n,&m)){
        for (int i=0; i<n; i++)  scanf("%s",a[i]);

        for (int i=0; i<n; i++){
            for (int j=0; j<m; j++)
                if (a[i][j] == '.')  cout << f(i,j);
                else  cout << "#";
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll x; cin >> x;
    ll res = 0;
    ll pre = 100;
    while(pre < x) {
        pre += (pre / 100);
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3644
object Main extends App {
  val n: Int = io.StdIn.readLine().toInt
  val arr: Array[Int] = io.StdIn.readLine().split(" ") map(_.toInt)
  val len: Int = 10000
  val count: Array[Int] = Array.fill(len+1)(0)
  val result: Array[Int] = Array.fill(n)(0)

  for (i <- arr) count(i) += 1
  for (i <- 1 until count.length) count(i) += count(i-1)
  for (i <- n-1 to 0 by -1) {
    result(count(arr(i))-1) = arr(i)
    count(arr(i)) -= 1
  }

  println(result.mkString(" "))
}

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

signed main() {
  int x,a,b;
  cin >> x >> a >> b;

  if(abs(x - a) < abs(x - b)) cout << "A" << endl;
  else cout << "B" << endl;
  return 0;
}

Measured memory_bytes: 3580
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

calc :: Int -> Int -> Int
calc 1 x = x
calc n x = calc (n - 1) ((n * x) `mod` (10 ^ 9 + 7))

mul' :: Int -> Int -> Int
mul' a b = a * b `mod` (10 ^ 9 + 7)

main = do
  [n, m] <- getIntList
  let diff = abs (n - m)
  if diff > 1
    then print 0
    else
      if diff == 0
        then print $ mul' (mul' (calc n 1) (calc m 1)) 2
        else print $ mul' (calc n 1) (calc m 1)


Measured memory_bytes: 14000
def check_num():
  if b-a > k or c-a > k or d-a > k or e-a > k or c-b > k or d-b > k or e-b > k or d-c > k or e-c > k or e-d > k:
    print(":(")
  else:
    print("Yay!")


a, b, c, d, e, k = [int(input()) for _ in range(6)]
check_num()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 2e5 + 10;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

ll n;

ll a, b;

int main() {
	speed;
	cin >> n;
	cin >> a >> b;
	for(int i = a; i <= b; i++)
		if(i % n == 0){
			cout << "OK\n";
			ex;
		}
	cout << "NG";
}

/*

0 133 14 135 28 137 42 139 56 141 70 143

*/



Measured memory_bytes: 3652
#include<stdio.h>

typedef struct {
	char m_aLetter[4];
}Squares;

int main(void) {
	int i;
	//構造体変数の定義
	Squares astSquares[3];

	//変数にアルファベットを入力
	scanf("%s", &astSquares[0].m_aLetter);
	scanf("%s", &astSquares[1].m_aLetter);
	scanf("%s", &astSquares[2].m_aLetter);

	printf("\n");
	//並んだアルファベットの中で左上、中央、右下の3つを順番に表示
	for (i = 0; i < 3; i++) {
		printf("%c", astSquares[i].m_aLetter[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
ll lcm(ll a,ll b)
{return a/gcd(a,b)*b;}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
ll INF=1e18;
//------------------------------------------------------------
int X,Y;

void solve() {

  cin >> X >>Y;

  if(Y%2 != 0 || X*2>Y || X*4<Y){
    print("No"); return;  }


  print("Yes");
  return;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

    long H;
    int N;
    long A;
    cin >> H >> N;


    for (int i = 0; i < N; ++i) {
        cin >> A;
        H -= A;
    }

    if (H <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  bool ok=true;
  if(a[0]!=0)ok=false;
  rep(i,n-1){
    if(a[i+1]>a[i]&&a[i+1]!=a[i]+1)ok=false;
  }
  if(ok==false){
    cout<<-1<<endl;
    return 0;
  }
  ll ans=0;
  rep(i,n-1){
    if(a[i+1]-a[i]==1)ans++;
    else {
      ans+=a[i+1];
    }
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
    string s1, s2, s3;
    while(cin>>s1>>s2>>s3){
        cout<<s1[0]<<s2[0]<<s3[0]<<endl;
    }
    return 0;
}


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

int32_t main()
{
    int n;
    cin>>n;
    vector<double>v(n,0.0);
    for(int i=0;i<v.size();i++)
    {
        cin>>v[i];
    }
    vector<vector<double>>dp(n+1,vector<double>(n+1,0.0));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
                dp[i][j]+=dp[i-1][j]*(1-v[i-1]);
            else
                dp[i][j]+=dp[i-1][j]*(1-v[i-1])+dp[i-1][j-1]*v[i-1];
        }
    }
    double sum=0;
    for(int i=n/2+1;i<=n;i++)
    {
        sum+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<sum<<endl;
}


Measured memory_bytes: 70656
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
void sort(int *x, int left, int right){
  int pivot,left_hold,right_hold;
  
  left_hold = left;
  right_hold = right;
  pivot = x[left];
  while(left < right){
    while((x[right]>=pivot)&&(left<right))
      right--;
    if(left!=right){
      x[left] = x[right];
      left++;
    }
    while((x[left]<=pivot)&&(left<right))
      left++;
    if(left!=right){
      x[right]=x[left];
      right--;
    }
  }
  x[left] = pivot;
  pivot = left;
  left = left_hold;
  right = right_hold;
  if(left<pivot)
    sort(x,left,pivot-1);
  if(right>pivot)
    sort(x,pivot+1,right);
}
main(){
  int N,K,count=0;
  scanf("%d%d",&N,&K);
  N--;
  while(N>0){
    count++;
    N-=K-1;
  }
  printf("%d\n",count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
const Int MOD = 1e9+7;

//---------- べき乗 ----------
Int power(Int a, Int n){
    if(a == 0) return 0;
    if(n == 0) return 1;
    
    Int res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % MOD;
        a = a * a % MOD; n /= 2;
    }
    return res;
}


int main(){
    Int N, K; cin >> N >> K;

    vector<Int> cnt(100010, 0); //cnt[i] = gcd = iとなる選び方

    Int ans = 0;
    for(int i = K; i>=1; i--){
        Int d = K/i;

        cnt[i] += power(d,N);
        for(int j=2; j*i<=K; j++){
            cnt[i] -= cnt[j*i];
            if(cnt[i] < 0) cnt[i] += MOD;
        }
        ans = (ans + (cnt[i] * i % MOD)) % MOD;
    }

    cout << ans << endl;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  vector<char> str1(s.size());
  vector<char> str2(t.size());
  rep(i, s.size()){
    str1[i] = s[i];
  }
  rep(i, t.size()){
    str2[i] = t[i];
  }
  sort(str1.begin(), str1.end());
  sort(str2.begin(), str2.end(), greater<char>());
  
  bool judge1 = 0;
  bool judge2 = 0;
  rep(i, str1.size()){
    if (str1[i] == str2[i]) {
      judge1 = 1;
      judge2 = 1;
    }
    else if (str1[i] < str2[i]) {
      judge1 = 1;
      break;
    }
    else {
      judge1 = 0;
      break;
    }
  }
  
  if (s == t) judge1 = 0;
  if (judge1 && judge2 && s.size() >= t.size()) judge1 = 0;
  
  if (judge1) cout << "Yes" << endl;
  else cout << "No" << endl;
      
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    reverse(all(s));
    vector<ll>c(n),m(n),cm(n),cmd(n);
    if(s[0]=='C')c[0]=1;
    if(s[0]=='M')m[0]=1;
    REP(i,1,n){
        if(s[i]=='C'){
            c[i]=c[i-1]+1;
            m[i]=m[i-1];
            cm[i]=cm[i-1];
        }
        else if(s[i]=='M'){
            c[i]=c[i-1];
            m[i]=m[i-1]+1;
            cm[i]=c[i-1]+cm[i-1];
        }
        else if(s[i]=='D'){
            c[i]=c[i-1];
            m[i]=m[i-1];
            cm[i]=cm[i-1];
            cmd[i]=cm[i-1];
        }else{
            c[i]=c[i-1];
            m[i]=m[i-1];
            cm[i]=cm[i-1];
        }
    }
    ll q;cin>>q;
    while(q){
        q--;
        ll k;cin>>k;
        ll ans=0;
        rep(i,n){
            if(s[i]=='D'){
                if(i-k<0){
                    ans+=cmd[i];
                }else{
                    ans+=cmd[i]-cm[i-k]-c[i-k]*(m[i]-m[i-k]);
                }
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 32644
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
 
s1 = 0
s2 = 0
 
for i in range(n):
    b[i] = a[i] - i
b.sort()
 
b1 = b[n//2]
b2 = b[n//2-1]
 
for i in range(n):
    s1 += abs(a[i] - b1 - i)
 
for i in range(n):
    s2 += abs(a[i] - b2 - i)
 
print(min(s1, s2))

Measured memory_bytes: 26708
#include <iostream>

using namespace std;

int main(){
    int N,Q;
    while(cin>>N>>Q && N|Q){
        int a[100]={};

        for(int i=0;i<N;i++){
            int m;cin>>m;
            for(int j=0;j<m;j++){
                int data;cin>>data;
                a[data]++;
            }
        }

        int ans=0;
        for(int i=0;i<100;i++){
            if(a[ans]<a[i]){
                ans=i;
            }
        }

        if(Q <= a[ans]){
            cout<<ans<<endl;
        }else{
            cout<<0<<endl;
        }
    }
}

Measured memory_bytes: 1160
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int N,a[22],L[22],H[22];
int memo[200010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N;
	rep(i,N)cin>>a[i];
	double lo = 0, hi = 1;
	rep(_,40){
		double mi = (lo+hi)/2;
		rep(i,N){
			L[i] = ceil(a[i] * (1 - mi));
			H[i] = floor(a[i] * (1 + mi));
		}
		vector<int> cur,nx;
		rep2(i,L[0],H[0]+1){
			cur.pb(i);
		}
		rep2(i,1,N){
			if(sz(cur) == 0)break;
			nx.clear();
			memset(memo,0,sizeof(memo));
			rep(j,sz(cur)){
				for(int k = (L[i] + cur[j] - 1) / cur[j] * cur[j];
					k <= H[i] / cur[j] * cur[j]; k += cur[j]){
					if(!memo[k]){
						nx.pb(k);
						memo[k] = 1;
					}
				}
			}
			cur = nx;
		}
		if(sz(cur)>0) hi = mi;
		else lo = mi;
	}
	cout<<fixed<<setprecision(16)<<hi<<endl;
}

Measured memory_bytes: 2844
n,m=map(int,input().split())
paths=[]
a=[]
b=[]
for i in range(n):
    paths.append([0]*n)
for i in range(m):
    a_i,b_i=map(int,input().split())
    paths[a_i-1][b_i-1]=1
    paths[b_i-1][a_i-1]=1
    a.append(a_i)
    b.append(b_i)
visited=[0]*n

def dfs(now):
    visited[now]=1
    for i in range(n):
        if paths[now][i]==1 and visited[i]==0:
            dfs(i)
    return

ans=0
for i in range(m):
    visited=[0]*n
    a_i=a[i]
    b_i=b[i]
    paths[a_i-1][b_i-1]=0
    paths[b_i-1][a_i-1]=0
    dfs(a_i)
    if sum(visited)!=n:
        ans+=1
    paths[a_i-1][b_i-1]=1
    paths[b_i-1][a_i-1]=1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split(' ');
		int a = int.Parse(str[0]);
		int b = int.Parse(str[1]);
		int c = int.Parse(str[2]);
		int t = 0;
		if(a > b){
			t = a;
			a = b;
			b = t;
		}
		if(b > c){
			t = b;
			b = c;
			c = t;
		}
		if(a > b){
			t = a;
			a = b;
			b = t;
		}
		Console.WriteLine(a + " " + b + " " + c);
	}
}


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <set>
#include <utility>
#include <climits>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

#define ll long long
#define ull unsigned long long
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	for (int i = 0, a; i < m; ++i) {
		cin >> a;
		n -= a;
	}
	cout << (n >= 0 ? n : -1);
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

int N;
ll A[MAX_N];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld", &A[i]);
	sort(A, A + N);
	if(N % 2 == 0){
		ll res = 0;
		for(int i = 0; i < N; i++){
			if(i < N / 2 - 1) res -= 2 * A[i];
			else if(i == N / 2 - 1) res -= A[i];
			else if(i == N / 2) res += A[i];
			else res += 2 * A[i];
		}
		printf("%lld\n", res);
	}else{
		ll res1 = 0, res2 = 0;
		for(int i = 0; i < N; i++){
			if(i < N / 2 - 1) res1 -= 2 * A[i];
			else if(i == N / 2 - 1 || i == N / 2) res1 -= A[i];
			else res1 += 2 * A[i];
		}
		for(int i = 0; i < N; i++){
			if(i < N / 2) res2 -= 2 * A[i];
			else if(i == N / 2 || i == N / 2 + 1) res2 += A[i];
			else res2 += 2 * A[i];
		}
		printf("%lld\n", max(res1, res2));
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	int res = 0;
	int in1;
	for (int i = 1; i <= n; i++) {
		cin >> in1;
		if (i % 2 == 1 && in1 % 2 == 1) { res++; }
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main()
{
    for (;;) {
        string str;
        getline(cin, str);
        if (str == ".")
            break;

        stack<int> s;
        string::iterator i;
        for (i = str.begin(); i != str.end(); ++i) {
            if (*i == '(') {
                s.push(1);
            } else if (*i == ')') {
                if (!s.empty() && s.top() == 1)
                    s.pop();
                else
                    break;
            } else if (*i == '[') {
                s.push(2);
            } else if (*i == ']') {
                if (!s.empty() && s.top() == 2)
                    s.pop();
                else
                    break;
            }
        }
        if (i == str.end() && s.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll sx, ll sy, ll tx, ll ty) {
  ll dx = tx - sx;
  ll dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');

  cout << string(dy, 'D') << string(dx, 'L');

  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';

  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll sx;
  scanf("%lld", &sx);
  ll sy;
  scanf("%lld", &sy);
  ll tx;
  scanf("%lld", &tx);
  ll ty;
  scanf("%lld", &ty);
  solve(sx, sy, tx, ty);
  return 0;
}


Measured memory_bytes: 3680