akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

using ll = long long;


bool solve() {
    int N, M, C, S, G;
    int x[10001], y[10001], d[10001], c[10001];
    vector<int> com[20];

    cin >> N >> M >> C >> S >> G;
    S--; G--;

    if (N == 0) return false;

    for(int i=0; i<M; i++) {
        scanf("%d%d%d%d", x+i, y+i, d+i, c+i);
        x[i]--; y[i]--; c[i]--;
        com[c[i]].push_back(i);
    }

    int p[30];
    int q1[30][51], q2[30][51];
    int cost[30][20010] = {};

    for(int i=0; i<C; i++) {
        scanf("%d", p+i);
    }

    for(int i=0; i<C; i++) {
        q1[i][0] = 0;
        q1[i][p[i]] = 1e9;
        for(int j=1; j<p[i]; j++) {
            scanf("%d", q1[i] + j);
        }
        for(int j=0; j<p[i]; j++) {
            scanf("%d", q2[i] + j);
        }
    
        int t = 0, s = 0;
        cost[i][0] = 0;

        for (int j=0; j<20001; j++) {
            if(q1[i][t] == j) {
                s = q2[i][t];
                t++;
            }

            cost[i][j+1] = cost[i][j] + s;
        }
    }

    ll Dist[101][101];

    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            Dist[i][j] = 1e17 * (i != j);
        }
    }

    for(int r=0; r<C; r++) {
        int dist[101][101];

        for(int i=0; i<N; i++)
            for(int j=0;j<N;j++)
                dist[i][j] = (i != j) * 1e9;
        
        for(int i : com[r])
            dist[x[i]][y[i]] = dist[y[i]][x[i]] = min(dist[x[i]][y[i]], d[i]);

        for(int k=0; k<N; k++) {
            for (int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
                }
            }
        }

        for(int i=0; i<N; i++) {
            for(int j=0;j<N; j++) {
                if(dist[i][j] < 1e8) {
                    Dist[i][j] = min(Dist[i][j], (ll)cost[r][dist[i][j]]);
                }
            }
        }
    }

    for(int k=0; k<N; k++) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
            }
        }
    }

    if (Dist[S][G] > 1e16)
        Dist[S][G] = -1;

    printf("%lld\n", Dist[S][G]);
    return true;
}

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


Measured memory_bytes: 6028
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    
    int n; cin >> n;
    n %= 10;
    if(n == 3) cout << "bon" << endl;
    else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    
    return 0;
}

Measured memory_bytes: 3596
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N,K;
    cin >> N >> K;
    int A[N];
    rep(i,N) cin >> A[i];
    int ball[N+1]={};
    int kind=0;
    rep(i,N) ball[A[i]]++;
    rep(i,N+1) if(ball[i]) kind++;
    sort(ball,ball+N+1);
    int ans=0,now=0;
    while(kind-K>0){
        if(ball[now]) ans+=ball[now],kind--;
        now++;
    }
    cout << ans << endl;
}

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

const Cost INF = 1e12;
using P = pair<Cost, int>;

struct Edge {
	int from, to;
	Cost cost;
	Edge() {}
	Edge(int f, int t, Cost c) : from(f), to(t), cost(c) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<Cost> Dijkstra(const Graph& G, int s) {
	int n = G.size();
	vector<Cost> d(n, INF);
	priority_queue<P, vector<P>, greater<P>> pq;
	pq.emplace(0, s);
	d[s] = 0;
	while (!pq.empty()) {
		auto p = pq.top(); pq.pop();
		if (p.first > d[p.second]) continue;
		for (auto e : G[p.second]) if (d[e.to] > p.first + e.cost) {
			pq.emplace(p.first + e.cost, e.to);
			d[e.to] = p.first + e.cost;
		}
	}
	return d;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int V, E, r;
	cin >> V >> E >> r;
	Graph G(V);
	for (int i = 0, s, t, d; i < E; i++) {
		cin >> s >> t >> d;
		G[s].emplace_back(s, t, d);
	}
	auto res = Dijkstra(G, r);
	for (auto ans : res) {
		if (ans == INF) puts("INF");
		else printf("%d\n", (int)ans);
	}
	return 0;
}

Measured memory_bytes: 19276
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long int ll;

int main(){
  int n, k; cin >> n >> k;
  vector<ll> line(n);

  rep(i, 0, n){
    cin >> line[i];
  }

  if(k<=0){
    cout << 0 << endl;
    return 0;
  }

  ll ans = pow(10, 18);
  rep(i, 0, n-k+1){
      ans = min(ans, min(llabs(line[i]), llabs(line[i+k-1])) + llabs(line[i+k-1]-line[i]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
while (s = gets.chomp.split(" ").map(&:to_i)) != [0,0]

n = s[0]
r = s[1]

#p n,r

    a = (1..n).to_a
    a = a.reverse
    
    r.times{
        s = gets.chomp.split(" ").map(&:to_i)
        b = a.shift(s[0]-1)
        c = a.shift(s[1])
        a = [c,b,a].flatten
        #p a 
    }

    puts a[0]
    
end 

Measured memory_bytes: 9192
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  b[n-1] = a[0]-a[n-1]+k;
  rep(i,n-1) b[i] = a[i+1]-a[i];
  
  int m = 0;
  rep(i,n) m = max(m,b[i]);
  
  dunk(k-m);
}
  

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

int asc(const void *A, const void *B) {
	if (*(int *)A > *(int *)B) return 1;
	if (*(int *)A < *(int *)B) return -1;
	return 0;
}

int main()
{
	int n[3];
	rep(i,3)
		cin >> n[i];
	int a = 0;
	int b = 0;
	int idx;
	qsort(n, sizeof(n) / sizeof(*n) , sizeof(int), asc);
	a = n[2] - n[0];
	b = n[2] - n[1];
	int ans  = 0;
	if (a % 2 == 0 && b % 2 == 0)
		ans = (a / 2) + (b / 2);
	else if (a % 2 && b % 2)
		ans = (a + b) / 2;
	else 
	{
		if (abs(a - b) == 1)
			ans = (max(a, b)) + 1;
		else if (abs(a - b) == 3)
			ans = max(a, b);
		else
			ans = (((a+1) / 2) + ((b+1) / 2)) + 1;
	}
	cout << ans << endl;
	return (0);
}

Measured memory_bytes: 256
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m;
    scanf("%lld %lld",&n,&m);
    int p[m],y[m];
    rep(i,m)scanf("%lld %lld",&p[i],&y[i]);
    vvi v(n+1);
    rep(i,m)v[p[i]].pb(y[i]);
    rep(i,n+1)SORT(v[i]);
    rep(i,m){
        int x=lower_bound(all(v[p[i]]),y[i])-v[p[i]].begin()+1;
        printf("%012lld\n",p[i]*1000000+x);
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 091 C / Link: http://abc091.contest.atcoder.jp/tasks/abc091_c  ----- */


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

	LL N; cin >> N;
	using tp = tuple<int, int, int>;
	vector<tp>events;
	FOR(i, 0, N) {
		LL x, y; cin >> x >> y;
		events.push_back(tp(x, y, 0));
	}

	FOR(i, 0, N) {
		LL x, y; cin >> x >> y;
		events.push_back(tp(x, y, 1));
	}
	SORT(events);
	multiset<int>Reds;
	LL ans = 0;
	for (auto e : events) {
		int x, y, id;
		tie(x, y, id) = e;
		if (id) { // blue
			auto it = Reds.lower_bound(y); 
			if (it != Reds.begin()) {
				it--;
				ans++;
				Reds.erase(it);
			}
		}
		else {
			Reds.insert(y);
		}
	}

	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  int W, H, N;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &N);
  int Sr, Sc;
  scanf("%d", &Sr);
  scanf("%d", &Sc);
  std::string S, T;
  std::cin >> S >> T;
  int safestep[4];
  char moji[4]={'U', 'R', 'D', 'L'};
  safestep[0]=Sr;
  safestep[1]=W-Sc+1;
  safestep[2]=H-Sr+1;
  safestep[3]=Sc;
  for (int i=0; i<4; i++){
    //printf("i=%d\n", i);
    int step=0;
    for (int j=0; j<N; j++){
      //printf("j=%d\n", j);
      if (S[j]==moji[i]){
	step++;
      }
      if (step>=safestep[i]){
	printf("NO\n");
	return 0;
      }
      if (T[j]==moji[(i+2)%4]){
	step=std::max(step-1, -safestep[(i+2)%4]+1);
      }
    }
  }
  printf("YES\n");

  return 0;
}


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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int road[2][200001];
map<int, int> mp[2000001];

int root(int x, int t) {
  return road[t][x] = road[t][x] == x ? x : root(road[t][x], t);
}

void unite(int x, int y, int t) {
  x = root(x, t);
  y = root(y, t);

  road[t][x] = y;
}

int main() {
  int n, k, l;
  cin >> n >> k >> l;

  rep(i, 0, n) road[0][i] = i, road[1][i] = i;

  rep(i, 0, k) {
    int p, q;
    cin >> p >> q;
    unite(p, q, 0);
  }

  rep(i, 0, l) {
    int r, s;
    cin >> r >> s;
    unite(r, s, 1);
  }

  rep(i, 1, n + 1) mp[root(i, 0)][root(i, 1)]++;
  rep(i, 1, n + 1) cout << mp[road[0][i]][road[1][i]] << endl;
}


Measured memory_bytes: 104448
#include<stdio.h>

int isPrime(int x){
  int i;
  if (x<2) return 0;
  else 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, i, x;
  int cnt=0;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%d", &x);
    if (isPrime(x)) cnt++;
  }
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 596
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();

    if a == b && b == c && c == a {
        return "Yes".to_string();
    }

    return "No".to_string();
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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);
    int n;
    cin >> n;
    vector<int> b(1e5+1,0);
    rep(i,n) {
        int a;
        cin >> a;
        if(a!=0) b[a-1]++;
        b[a]++;b[a+1]++;
    }
    int ans=0;
    rep(i,b.size()) chmax(ans, b[i]);
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] A = new boolean[10000];
        for(int i = 0;i < 10000;i++)A[i] = false;
        int count = 1;
        A[n - 1] = true;
        while(true){
            if(n % 2 == 0) n /= 2;
            else n = 3 * n + 1;
            if(A[n - 1] == true){
                break;
            }else{
                A[n - 1] = true;
                count += 1;
            }
        }
        System.out.println(count + 1);
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
#include<string.h>

int main(void){

  char S[100001];
  int zero = 0 , one = 0;         //0と1の個数
  scanf("%s", S);
  int len = strlen(S);            //文字列の長さ

  for(int i = 0 ; i < len ; i++){

    if(S[i] == '0'){
      zero++;
    }else if(S[i] == '1'){
      one++;
    }

  }

  int ans = (zero < one) ? zero * 2 : one * 2;

  printf("%d", ans );


  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int p[3];
  for (int i=0; i<3; i++) cin >> p[i];
  sort(p,p+3);
  int cnt = 0;
  for (int i=0; i<2; i++) {
    if (p[i+1] != p[i]) {
      cnt++;
    }
  }
  cout << cnt+1 << endl;
} 
  

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int[] data = new int[n];
      double sum = 0;

      for (int i = 0;i<n;i++ ) {
      data[i] = sc.nextInt();
      sum = sum + (double)1/data[i];
      }

      System.out.println(1/sum);
  }

}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  int cnt = 0;
  int hmax = *max_element(h.begin(), h.end());
  for (int i = 0; i < hmax; i++) {
    bool flag = false;
    for (int j = 0; j < n; j++) {
      if (h[j] == 0) flag = false;
      else {
        if (!flag) {
          flag = true;
          cnt++;
        }
        h[j]--;
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
import heapq
import math

n, h = map(int, input().split())
katana = [list(map(int, input().split())) for _ in range(n)]

max_a = -1
max_b = -1 # aが最大の刀のb
max_i = -1
for i in range(n):
    a, b = katana[i]
    if a > max_a:
        max_a = a
        max_i = i
    elif a == max_a and b < max_b:
        max_i = i
        max_b = b

nagetsuke = []
for i in range(n):
    a, b = katana[i]
    if b >= max_a:
        heapq.heappush(nagetsuke, -b)

ans = 0
damage = 0
while damage < h and len(nagetsuke) > 0:
    q = heapq.heappop(nagetsuke)
    damage -= q
    ans += 1

if len(nagetsuke) == 0:
    a, b = katana[max_i]
    if damage < h:
        ans += math.ceil((h-damage)/a)

print(ans)

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

# 値がiであるようなA_iの個数を格納する
val_count = [0] * (10 ** 5 + 1)

total_A = 0
for a in A:
    total_A += a
    val_count[a] += 1

S = []
for i in range(Q):
    B, C = map(int, input().split())
    B_count = val_count[B]
    total_A -= B * B_count
    total_A += C * B_count
    S.append(total_A)

    val_count[B] = 0
    val_count[C] += B_count

for s in S:
    print(s)


Measured memory_bytes: 87308
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
	private static final long MOD = 1_000_000_007;
	long[][] dp = null;
	
	public long get(String L, int N, int upper) {
		if (upper >= 1) {
			upper = 1;
		}
		if (dp[N][upper] != -1) {
			return dp[N][upper];
		} else {
			int max = 0;
			max += upper * 2;
			if (L.charAt(N) == '1') {
				max += 1;
			}
			
			long count = 0;
			// use 0
			count = (count + get(L, N+1, max)) % MOD;
			
			// use 1
			if (max >= 1) {
				count = (count + get(L, N+1, max-1)) % MOD;
				count = (count + get(L, N+1, max-1)) % MOD;
			}
			dp[N][upper] = count;
			return count;
		}
	}
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		String L = in.next();
		in.close();

		int N = L.length();
		
		dp = new long[N][2];
		for (int i=0; i<N; i++) {
			Arrays.fill(dp[i], -1);
		}
		if (L.charAt(N-1) == '0') {
			dp[N-1][0] = 1L;
			dp[N-1][1] = 3L;
		} else {	// '1'
			dp[N-1][0] = 3L;
			dp[N-1][1] = 3L;
		}
		
		for (int n=N-1; n>=0; n--) {
			get(L, n, 0);
			get(L, n, 1);
		}
		
		long ret = get(L, 0, 0);
		
		System.out.println(ret);
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
 
}


Measured memory_bytes: 28992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());

    int ans = d[n/2] - d[n/2 - 1];
    cout << ans << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int> 
#define ppp pair<pii,pii>
#define pb push_back
#define N 200003
#define inf (ll)1e9+11
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;

signed main()
{
    warmup
    
    string s;
    cin>>s;
    bool f=0,f1=0;
    f=(s[0]=='A' or s[1]=='A' or s[2]=='A');
    f1=(s[0]=='B' or s[1]=='B' or s[2]=='B');
    cout<<((f&f1) ? "Yes":"No");
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long H, long long W){
    if(H==1||W==1){cout<<1<<endl;}
    else
        cout<<(H*W+1)/2<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


H, W = na()
c = [na() for _ in range(10)]
A = [na() for _ in range(H)]
adj = [[] for _ in range(10)]



# cost[i][j]: 頂点v_iから頂点v_jへ到達するための辺コストの和
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
for y in range(H):
    for x in range(W):
        if A[y][x] != -1:
            #print(ans)
            ans += c[A[y][x]][1]
print(ans)



Measured memory_bytes: 37992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, g, b ;
  cin >> r >> g >> b;
  if ((100 * r + 10 * g + b) % 4 == 0) { cout << "YES" << endl; }
  else { cout << "NO" << endl; }
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())

a = list(map(int, input().split()))
c = Counter(a)

# print(c)
tmpsum = sum(a)

q = int(input())

for i in range(q):
    ans = tmpsum
    before, after = map(int, input().split())

    num_of_before = c[before]
    # print(c[before])

    ans += num_of_before * (after - before)
    tmpsum = ans

    c[after] += num_of_before
    c[before] = 0
    print(ans)


Measured memory_bytes: 87684
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int N=gi();
        int X=gi();
        int M=0;

        int min=Integer.MAX_VALUE;
 
        for (int i=0; i<N;i++) {
            int m=gi();
            M+=m;
            if(m<min) {
            	min=m;;
            }
        }
        
        int k=N;
        X=X-M;
        
        while(X>=min) {
        	X-=min;
        	k++;
        }


	    System.out.println(k);

//	    if (isNumber(s1) && isNumber(s2) && s.charAt(a) == '-') {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35460
#32 2020/07/14
N = int(input())
S = list(input())
count = 0
max = 0
for i in range(N):
  if S[i] == 'D':
    count -= 1
  elif S[i] == 'I':
    count += 1
  if count > max:
    max = count
print(max)

Measured memory_bytes: 9076
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    println!("{}", n * n * n);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int N = 1000100;
vector <int> prime;//i番目の素数
bool is_prime[1000100]; //is_prime[i] がTrueならiは素数

int sieve(int n){
  int p = 0;
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++){
    if (is_prime[i]){
      prime.emplace_back(i);
      for (int j = 2*i; j <=n; j+=i) is_prime[j] = false;
    }
  }
  return p;//pは素数の数
}

int main(){
  sieve(N);
  int n; cin >> n;
  vector<int>a(n);
  vector<int>c(N);
  rep(i, n){
    cin >> a[i];
    c[a[i]]++;
  }
  bool flag = true;
  for (int i:prime){
    int cnt = 0;
    for (int j = i; j <= N; j+=i){
      cnt += c[j];
    }
    if (cnt > 1){
      flag = false;
      break;
    }
  }
  int gcd = a[0];
  rep(i, n-1){
    gcd = __gcd(a[i+1], gcd);
  }
  if (flag) cout << "pairwise coprime" << endl;
  else if (gcd == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
}

Measured memory_bytes: 12308
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,x,a;
	
	int i;
	int r;
	
	int j,k;
	
	cin>>n>>x;
	cin>>a;
	j=abs(x-a);
	//cout<<j<<endl;
	for(i=0;i<n-1;i++){
		cin>>a;
		k=abs(x-a);
		//cout<<j<<" "<<k<<endl;
		if(j<k){
			swap(j,k);
		}
		while(1){
			r=j%k;
			if(r==0){
				break;
			}
			j=k;
			k=r;
		}
		j=k;
	}
		
	
	
		
	
	cout<<j<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

ll lucas(ll n)
{
	static vector<ll>memo(87, -1);
	if (memo[n] != -1) {
		return memo[n];
	} else if (n == 0) {
		return 2;
	} else if (n == 1) {
		return 1;
	} else {
		return (memo[n - 1] = lucas(n - 1)) + (memo[n - 2] = lucas(n - 2));
	}
}
int main()
{
	cout << lucas(in()) << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N
for n in range(N):
    A[n] = int(input())

maximum = max(A)
second_maximum = sorted(A, reverse=True)[1]
for n in range(N):
    if A[n] == maximum:
        print(second_maximum)
    else:
        print(maximum)

Measured memory_bytes: 13284
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){

	ll n;
	cin >> n;
	vll b(n-1);
	rep(i,n-1)cin >> b[i];

	if(n == 2){
		cout << 2*b[0] << endl;
		return 0;
	}

	ll ans = b[0]+b[n-2];
	rep(i,n-2){
		ans += min(b[i],b[i+1]);
	}
	cout << ans << endl;


	

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc140.contest.atcoder.jp/tasks/abc140_a

Measured memory_bytes: 256
n = int(input())
s = str(input())
ans = 0
ans_lis = [0]

for i in range(n):
    if s[i] == "I":
        ans += 1
        ans_lis.append(ans)
    else:
        ans -= 1
        ans_lis.append(ans)

print(max(ans_lis))

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 998244353
#define ep 0.000000001
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
//#define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

vector<int>path[1000010];
int level[100010], vis[100010];
void bfs(int start)
{
    queue<int>q;
    level[start]=0;
    q.push(start);
    vis[start]=1;
    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        for(int i=0;i<path[v].size();i++)
        {
            if(vis[path[v][i]]==0)
            {
                level[path[v][i]]=level[v]+1;
                vis[path[v][i]]=1;
                q.push(path[v][i]);

            }
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int n, e, n1, n2, c=0, cnt=0;  
    cin>>n>>e; map <int, int> mp;
    for(int i=0;i<e;i++){
        cin>>n1>>n2; mp[n1]=-1; mp[n2]=-1;
        path[n1].push_back(n2);
        path[n2].push_back(n1);
    }
    for(int i=1;i<=n;i++){
        if(mp[i]==0)cnt++;
        else if(vis[i]==0)c++,bfs(i);
    }
    ll ans=0; 
    ans+=cnt; if(c>1)ans+=(c-1);
    cout<<ans<<endl;
    //for(int i=1;i<=n;i++) cout<<i<<" "<<level[i]<<endl;
    return 0;
}

Measured memory_bytes: 35332
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    int n, k;

    cin >> n >> k;

    double ans = 0.0;

    for(int i = 1; i <= n; i++) {
        double t = 1.0/n;
        int s = i;
        while(s < k) {
            s *= 2;
            t /= 2;
        }
        ans += t;
    }

    cout << ans << endl;
  
    return 0;
}



Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;
#define SORTVL(v) sort(v.begin(), v.end());
#define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>());

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }
// 末尾数字で切り上げ
LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; }
//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	cin >> N;
	O(ceil(N / 2.0));

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int a,b,c,k;
    cin >> a >> b >> c>>k;
    if(k<a)print(k);
    else if(k<=a+b) print(a);
    else print(a-(k-a-b));
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
a = sorted([int(input()) for _ in range(n)])

if n % 2 == 0:
    ans = 2 * (sum(a[n // 2:]) - sum(a[:n // 2]))
    ans += a[n // 2 - 1] - a[n // 2]
    print(ans)
elif n % 2 == 1:
    ans = 2 * (sum(a[n // 2 + 1:]) - sum(a[:n // 2]))
    print(max(ans + a[n // 2] - a[n // 2 + 1],
              ans - a[n // 2] + a[n // 2 - 1]))


Measured memory_bytes: 14184
// #pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const ll infll=1e18+9;
const int infint=1e9+7;
const int MAXN=1e6+7;
const double eps=1e-9;
const long double pi=3.1415926535897932384626433832795;
const long double e=2.71828182845904523536028747135266;
inline ll read()
{
    ll kr=1,xs=0;char ls;ls=getchar();
    while(!isdigit(ls)){
        if(!(ls^45)) kr=-1;ls=getchar();
    }
    while(isdigit(ls)){
        xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
    }
    return xs*kr;
}
// inline __int128 read128()
// {
//     __int128 kr=1,xs=0;char ls;ls=getchar();
//     while(!isdigit(ls)){
//         if(!(ls^45)) kr=-1;ls=getchar();
//     }
//     while(isdigit(ls)){
//         xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
//     }
//     return xs*kr;
// }
inline ull readull()
{
    ull xs=0;char ls;ls=getchar();
    while(!isdigit(ls)) ls=getchar();
    while(isdigit(ls)){
        xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
    }
    return xs;
}
inline void writeull(ull x){
    if(x<0){x*=-1;putchar('-');}
    if(x>=10) writeull(x/10);
    putchar('0'+x%10);
}
inline void write(ll x){
    if(x<0){x*=-1;putchar('-');}
    if(x>=10) write(x/10);
    putchar('0'+x%10);
}
// inline void write(__int128 x){
//     if(x<0){x*=-1;putchar('-');}
//     if(x>=10) write(x/10);
//     putchar('0'+x%10);
// }
///////////////////////////////////////////////////////////////////////////////////////

int mp[1009][26],mmp[26];
int main()
{
    int t=1;
    // t=read();
    while(t--){
        string a,b;
        cin >> a >> b;
        int n=a.size(),m=b.size(),ans=mod;
        for (int i=0;i<=n-m;i++){
            int cnt=0;
            for (int j=0;j<m;j++){
                if(a[i+j]!=b[j]) cnt++;
            }
            ans=min(ans,cnt);
        }
        cout << ans << endl;
    }
    return 0 ;
}

/*
6
011000010010000001100001011000010000101001100001
*/


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;


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

     string S;
    cin >> S;
    int A = 0;

    REP(i,4){
        if(S[i] == '+'){ 
            A=A+1;
        } else{
            A=A-1;
        }
    }
    cout << A << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())
v = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    v.append(list([a, b, c, d]))

ans = 0
for i in itertools.combinations_with_replacement(range(1, m + 1), n):
    temp = 0
    for j in v:
        if (i[j[1]] - i[j[0]] == j[2]):
            temp += j[3]
    ans = max(ans,temp)
print(ans)


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

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

    int n = s.length();
    int res = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n-1-i]) res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int i,j,c=0;
int m,n;
char rbq;
char map[101][101];
void dfs(char map[101][101],int i,int j)
{
    map[i][j]='.';
    if(i-1>-1&&map[i-1][j]==rbq)
        dfs(map,i-1,j);
    if(i+1<m&&map[i+1][j]==rbq)
        dfs(map,i+1,j);
    if(j-1>-1&&map[i][j-1]==rbq)
        dfs(map,i,j-1);
    if(j+1<n&&map[i][j+1]==rbq)
        dfs(map,i,j+1);
}
int main()
{
    while(scanf("%d%d",&m,&n)&&m)
    {
        c=0;
        for(i=0;i<=m-1;i++)
            scanf("%s",map[i]);
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            {
                if(map[i][j]!='.')
                {
                    rbq = map[i][j];
                    dfs(map,i,j);
                    c++;
                }
            }
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 3876
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))

    npa = ct([i+1+j for i, j in enumerate(a)])
    nma = ct([i+1-j for i, j in enumerate(a)])

    cnt = 0

    for i, j in npa.items():
        cnt += j*nma[i]
    print(cnt)


main()

Measured memory_bytes: 143444
#include <stdio.h>
int main()
{
    int d;
    int c[30];
    int last[30] = {};
    int s[400][30];
    int t[400];
    int v[400];
    scanf("%d", &d);
    for (int i = 1; i <= 26; i++)
    {
        scanf("%d", &c[i]);
    }
    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            scanf("%d", &s[i][j]);
        }
    }
    for (int i = 1; i <= d; i++)
    {
        scanf("%d", &t[i]);
    }
    v[1] = s[1][t[1]];
    last[t[1]] = 1;
    for (int j = 1; j <= 26; j++)
    {
        v[1] -= c[j] * (1 - last[j]);
    }
    printf("%d\n", v[1]);
    for (int i = 2; i <= d; i++)
    {
        v[i] = v[i - 1] + s[i][t[i]];
        last[t[i]] = i;
        for (int j = 1; j <= 26; j++)
        {
            v[i] -= c[j] * (i - last[j]);
        }
        printf("%d\n", v[i]);
    }
    return 0;
}

Measured memory_bytes: 1752
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

//補グラフをとるとクリークと独立集合は互いに移りあう

int n, m;
int G[2000][2000];

bool isbipartite = true;
int color[2000];
int colornum[2];

void dfs(int v, int c) {
    color[v] = c;
    colornum[c] ++;
    rep(i, n) {
        if(i == v || !G[v][i]) continue;
        if(color[i] == -1) dfs(i, 1 - c);
        else if(color[i] == c) isbipartite = false;
    }
}


void solve() {
    cin >> n >> m;
    rep(i, n) {
        rep(j, n) {
            G[i][j] = 1;
        }
    }
    rep(i, m) {
        int a, b; cin >> a >> b;
        a --; b --;
        G[a][b] = G[b][a] = 0;
    }
    vector<P> nums;
    rep(i, n) color[i] = -1;
    rep(v, n) {
        if(color[v] != -1) continue;
        colornum[0] = colornum[1] = 0;
        dfs(v, 0);
        nums.pb(P(colornum[0], colornum[1]));
    }
    
    if(!isbipartite) {
        cout << -1 << endl;
        return;
    }

    bool dp[2000];
    rep(i, n) dp[i] = 0;
    dp[0] = 1;
    for(auto p : nums) {
        for(int j = n; j >= 0; j--) {
            if(!dp[j]) continue;
            dp[j] = 0;
            dp[j + p.fr] = 1;
            dp[j + p.sc] = 1;
        }
    }
    int a = -1;
    int mid = n;
    rep(i, n + 1) {
        if(!dp[i]) continue;
        if(mid > abs(i - n / 2)) mid = abs(i - n / 2), a = i;
    }
    int b = n - a;
    cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 6144