akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		long x = in.nextLong();
		long[] a = new long[n];
		long[] b = new long[n];
		for (int i=0; i<n; i++) {
			a[i] = b[i] = in.nextLong();
		}

		long ans = Long.MAX_VALUE;
		for (int k=0; k<n; k++) {
			long sum = 0;
			for (int i=0; i<n; i++) {
				if (k != 0)
					b[i] = Math.min(b[i], a[(i-k+n)%n]);
				sum += b[i];
			}
			ans = Math.min(ans, k*x + sum);
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 13672
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int x = sc.nextInt();
      ans += Math.min(x * 2, (k - x) * 2);
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21460
from collections import deque

n = int(input())

result = deque()
index = 0

def front_enque(i):
    global result, index
    result.appendleft(i)
    index += 1

def enque(i):
    global result, index
    result.append(i)
    index += 1

if n % 2 == 0:
    for i in input().split():
        if index % 2 == 1:
            front_enque(i)
        else:
            enque(i)
else:
    for i in input().split():
        if index % 2 == 1:
            enque(i)
        else:
            front_enque(i)

print(" ".join(result))

Measured memory_bytes: 26564
using System;

namespace AtCoderSnippet
{
    class Program
    {
        static void Main(string[] args)
        {

            var S = Console.ReadLine();
            if (S == "RSS" ||
                S == "SRS" ||
                S == "SSR" ||
                S == "RSR")
            {
                Console.WriteLine("1");
            }
            else if (S == "RRS" ||
                S == "SRR")
            {
                Console.WriteLine("2");
            }
            else if (S == "RRR")
            {
                Console.WriteLine("3");
            }
            else
            {
                Console.WriteLine("0");
            }
        }
    }
}


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

int main() {
  string S;
  cin >> S;
  bool b = true;
  for(int i = 0;i<S.size();i++){
    int n = i % 2;
    if(n == 0 && S.at(i) == 'L') //奇数
    {
      b = false;
      break;
    }
    if(n == 1 && S.at(i) == 'R') //偶数
    {
      b = false;
      break;
    }
  }
  if(b == true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

vector<ll> as;

int main(void) {
    int N;
    cin >> N;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    reverse(as.begin(), as.end());

    queue<ll> pq;
    pq.push(as[0]);

    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ll v = pq.front();
        pq.pop();

        ans += v;
        pq.push(as[i]);
        pq.push(as[i]);
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6408
import copy
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
plus=[]
minus=[]
for a,b in zip(A,B):
	if a < b:
		minus.append(b - a)
	elif b < a:
		plus.append(a - b)
plus.sort(reverse=True)
p = 0
m = 0
befor = copy.deepcopy(plus)
while m != len(minus):
	if p == len(plus):
		print(-1)
		exit()
	if plus[p] > minus[m]:
		plus[p] -= minus[m]
		m += 1
	elif plus[p] == minus[m]:
		p += 1
		m += 1
	else: #plus[p] < minus[m]
		minus[m] -= plus[p]
		p += 1
ans = len(minus)
if plus[p] != befor[p]:
	ans += p + 1
else:
	ans += p
print(ans)

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, M; cin >> N >> M;

  vector<string> a(N);rep(i, N) cin >> a[i];
  vector<string> b(M);rep(i, M) cin >> b[i];

  bool ok = false;

  rep(i, N - M + 1) {
    rep(j, N - M + 1) {
      bool chk = true;
      rep(k, M) {
	string sa = a[i + k].substr(j, M);
	//	cout << "[" << sa << ":" << b[k] << "]" << endl;
	if(sa != b[k]) chk = false;
      }
      if(chk) ok = true;
    }
  }

  
  cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  int n;cin>>n;
  string s;cin>>s;
  int q;cin>>q;
  rep(t,q){
    int k;cin>>k;
    ll dp[4];
    rep(j,4){
      dp[j] = 0;
    }
    
    int bi = 0;
    int ei = 0;
    while(ei < k){
      if(s[ei] == 'D'){
        dp[0]++;
      }else if(s[ei] == 'M'){
        dp[2] += dp[0];
        dp[1]++;
      }else if(s[ei] == 'C'){
        dp[3] += dp[2];
      }
      ei++;

    }

    while(ei<n){
      if(s[bi] == 'D'){
        dp[0]--;
        dp[2] -= dp[1];
      }else if(s[bi] == 'M'){
        dp[1]--;
      }
      bi++;

      if(s[ei] == 'D'){
        dp[0]++;
      }else if(s[ei] == 'M'){
        dp[2] += dp[0];
        dp[1]++;
      }else if(s[ei] == 'C'){
        dp[3] += dp[2];
      }
      ei++;
      rep(j,4){
        //cout<<dp[j]<<" ";
      }
      //cout<<endl;
    }
    cout<<dp[3]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1948
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main()
{
  ll x; cin >> x;
  ll dep = 100;
  int year = 0;

  while (dep < x) {
    dep *= 1.01;
    year++;
  }

  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a = [a1, a2, a3]
n = int(input())
b = []
bng = 0
for i in range(n):
    bn = int(input())
    b.append(bn)
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            a[i][j] = -5
for i in range(3):
    if sum(a[i]) == -15:
        bng = 1
for i in range(3):
     cnt = 0
     for j in range(3):
       cnt += a[j][i]
       if cnt == -15:
         bng = 1
        
cnt = 0
for i in range(3):
        cnt += a[i][i]
if cnt == -15:
        bng = 1 
if a[0][2] + a[1][1] + a[2][0] == -15:
    bng = 1
                
if bng == 1:
    print("Yes")
else:
    print("No")

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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    ull ANS = 0, stopT = 0, T, t;
    uint N;
    scanf("%u %llu", &N, &T);
    uint i;
    REP(i, N){
        scanf("%llu", &t);
        if(stopT < t){
            ANS += T;
            stopT = t + T;
        }else{
            ANS += (T + t - stopT);
            stopT = t + T;
        }
    }
    printf("%llu\n", ANS);
    return 0;
}

Measured memory_bytes: 128
s = str(input())
alphabet = ["a","b","c","d","e","f"
,"g","h","i","j","k","l","m","n",
"o","p","q","r","s","t","u","v","w","x","y","z"]

for i in s:
    if i in alphabet:
        alphabet.remove(i)
if len(alphabet)!=0:
    print(alphabet[0])
else:
    print("None")

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n; cin >> n;
  vector<pair<string,pii>> s(n);
  rep(i,n){
    cin >> s[i].first >> s[i].second.first;
    s[i].second.first *= -1;
    s[i].second.second = i+1;
  }
  sort(all(s));
  
  rep(i,n){
    cout << s[i].second.second << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int A = Integer.parseInt(S[0]);
    int B = Integer.parseInt(S[1]);
    
    int ans = B;
    if(A <= 5){
      ans = 0;
    }else if(A <= 12){
      ans = B/2;
    }
    
    System.out.println(ans);
  }
}

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

flg=0
while(True):
    C -= B
    if C <=0:
        print("Yes")
        flg = 1
    if flg:
        break
    A -= D
    if A <=0:
        print("No")
        flg = 1
    if flg:
        break

Measured memory_bytes: 9160
#include <iostream>
using namespace std ;
int main()
{
	int r=0 , c=0 , in=0 , a=0 ;
	cin >> r >> c ;
	int rc[r+1][c+1] ;
	for(int i=0;i<r;i++)
	{
		for(int ia=0;ia<c;ia++)
		{
			cin >> in ;
			rc[i][ia]=in ;
		}
	}
	for(int i=0;i<r;i++)
	{
		for(int ia=0;ia<c;ia++)
		{
			a=a+rc[i][ia] ;
			if(ia==c-1) rc[i][ia+1]=a ;
		}
		a=0 ;
	}
	for(int i=0;i<c;i++)
	{
		for(int ia=0;ia<r;ia++)
		{
			a=a+rc[ia][i] ;
			if(ia==r-1) rc[ia+1][i]=a ;
		}
		a=0 ;
	}
	for(int i=0;i<r;i++)
	{
		a=a+rc[i][c] ;
		if(i==r-1) rc[r][c]=a ;
	}
	for(int i=0;i<=r;i++)
	{
		for(int ia=0;ia<=c;ia++)
		{
			cout << rc[i][ia] ;
			if(ia!=c) cout << " " ;
		}
		cout << endl ;
	}
	return 0 ;
}



Measured memory_bytes: 3124
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    int even = 1;
    REP(i, N) {
        if (a[i] % 2 == 0)
            even *= 2;
    }
    int ans = 1;
    REP(i, N) ans *= 3;

    ans -= even;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include        "iostream"
#include        "algorithm"
#include		"numeric"
#include        "cstring"
#include        "math.h"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        <ext/pb_ds/assoc_container.hpp> // Common file
#include        <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include        <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          db(x) cout<<#x <<" : "<< x <<endl;
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);   
	    freopen("ou.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q,W;
string s;
int dp[N];

void go()
{
	cin >> n >> W;

	vi w(n+1,0) , v(n+1,0);

	fo(i,0,n) // first -> weight , second  -> value
	{
		cin >> w[i] >> v[i];
	}

	fo(i,0,n)
	{
		for( int j = W - w[i]; j >= 0 ; j--)
		{
			dp[j+w[i]] = max( dp[j+w[i]] , dp[j] + v[i] );
			// bug(dp[j+w[i]]);
		}
	}

	int ans = 0;
	fo(i,0,W+1) ans = max( ans , dp[i] );

	cout << ans << endl;
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}


Measured memory_bytes: 1024
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }

  int ans;
  for (int sa = 0; sa <= 100; sa++) {
    bool flag = true;
    for (auto &pi : p) {
      if (pi == x - sa) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = x - sa;
      break;
    }

    flag = true;
    for (auto &pi : p) {
      if (pi == x + sa) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = x + sa;
      break;
    }
  }
  cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll sum = 0;
	rep(i,n){
		if(a[i+1] < a[i]){
			sum += a[i] -a[i+1];
			a[i+1] += a[i] -a[i+1];
		}
		// cout << a[i] << endl;
 	}
 	cout << sum - a[n-1] << endl;
}

Measured memory_bytes: 3988
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define x first
#define y second 
using namespace std;
int w,h,n;
struct P{int x,y;
friend bool operator<(P a,P b) {return a.x==b.x?a.y<b.y:a.x<b.x;}}p[300010];
 
int mx[1200010],tag[1200010];
int tp1,tp2,nxt;
pair<int,int> l[300010],r[300010];
void downtag(int k){mx[k<<1]+=tag[k];mx[k<<1|1]+=tag[k];
tag[k<<1]+=tag[k];tag[k<<1|1]+=tag[k];tag[k]=0;}
void modify(int k,int l,int r,int askx,int asky,int x)
{
    if (askx<=l&&r<=asky) {tag[k]+=x;mx[k]+=x;return;}
    int mid=(l+r)/2;
    if (tag[k]) downtag(k);
    if (askx<=mid) modify(k<<1,l,mid,askx,asky,x);
    if (asky>mid) modify(k<<1|1,mid+1,r,askx,asky,x);
    mx[k]=max(mx[k<<1],mx[k<<1|1]);
}
int ans=0;
void solve()
{
    memset(mx,0,sizeof(mx));
    memset(tag,0,sizeof(tag));
    sort(p+1,p+n+1);
    tp1=tp2=0;
    for (int i=1;i<=n;i++)
    {
        if (p[i].y<=h/2)
        {
            nxt=i-1;
            while (tp1&&p[i].y>l[tp1].y)
            {
                modify(1,1,n,l[tp1].x,nxt,l[tp1].y-p[i].y);
                nxt=l[tp1].x-1;tp1--;
            }
            if (nxt!=i-1) l[++tp1]=make_pair(nxt+1,p[i].y);
        }
        else
        {
            nxt=i-1;
            while (tp2&&p[i].y<r[tp2].y)
            {
                modify(1,1,n,r[tp2].x,nxt,p[i].y-r[tp2].y);
                nxt=r[tp2].x-1;tp2--;
            }
            if (nxt!=i-1) r[++tp2]=make_pair(nxt+1,p[i].y);
        }
        l[++tp1]=make_pair(i,0);
        r[++tp2]=make_pair(i,h);
        modify(1,1,n,i,i,h-p[i].x);
        ans=max(ans,p[i+1].x+mx[1]);
    }
}
int main()
{
    scanf("%d%d%d",&w,&h,&n);
    for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
    p[++n]=P{0,0};p[++n]=P{w,h};
    solve();
    for (int i=1;i<=n;i++) swap(p[i].x,p[i].y);swap(w,h);
    solve();
    printf("%d",ans<<1);
}

Measured memory_bytes: 15616
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}

void solve()
{
	int n   ,r ; 
	cin>>n>>r ; 
	if(n>=10){
		cout<<r<<endl;
	}
	else{
		cout<<r+100*(10-n)<<endl;
	}
}
 
int main() {
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int temp = N;
  int sum = 0;
  while(temp) {
    sum += temp % 10;
    temp = temp / 10;
  }
  if(N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int k, x;
   cin >> k >> x;
   if(500*k>=x) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Description: ????????????
// Verifyed: various problem 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}


// Circle // verified: AOJ 1183 
enum RCC{OUT=2,ON_OUT=1,ISC=0,ON_IN=-1,IN=-2};
int rcc(C a,C b){ R d=abs(a.c-b.c);return sgn(d-a.r-b.r)+sgn(d-abs(a.r-b.r));}


// cross point between circle and line 
// verified: AOJ CGL_7_D
P cir(C c,R t){return c.c+polar(c.r,t);}
VP cross(C c, L l){
	P h=proj(l,c.c),e=polar(sq(norm(c.r)-norm(h-c.c)),arg(l.t-l.s));
	return VP{h-e,h+e};
}

int main(void){
	int q;
	C c;
	cin >> c.c >> c.r;
		
	cin >> q;
	cout.precision(20);
	rep(i,q){
		P a,b;
		cin >> a >> b;
		L l={a,b};
		VP res=cross(c,l);
		if(real(res[0])>real(res[1])) swap(res[0],res[1]);
		if(sgn(real(res[0])-real(res[1]))==0 and imag(res[0])>imag(res[1])) swap(res[0],res[1]);
		cout << fixed << res[0] << " " << res[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back 
ll M=1e9+7;
using namespace std;
ll power(ll x,ll y)
{ 
    ll res = 1;  
    x = x % M; 
    while (y > 0) 
    { 
        if (y & 1)  res = (res*x) % M; 
        y = y>>1; 
        x = (x*x) % M;   
    } 
    return res;
}
int main()
{
	ll n,k,i,x,y;
	cin>>n>>k;
	x=n-k+1;
	y=1;
	for(i=1;i<=k;i++)
	{
		cout<<( x * y )%M<<"\n";
		x=( ( x * (n-k+1-i) )%M * power(i+1,M-2) )%M;
		y=( ( y * (k-i) )%M * power(i,M-2) )%M;
	}
	return 0;
}

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

#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int> pp;
    for(int i = 0; i < N; i++){
        int tmp;
        cin>>tmp;
        pp.emplace_back(tmp);
    }
    sort(pp.begin(), pp.end());
    int sum = accumulate(pp.begin(), pp.end(), 0);
    sum -= pp[pp.size()-1]/2;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)

# W = [i for i, x in enumerate(S) if x == 'W']
# B = [i for i, x in enumerate(S) if x == 'B']
#
# print(sum([len([b for b in B if b < w]) for w in W]))

dp = [0] * (N + 1)
ans = 0
for i in range(1, N + 1):
    if S[i-1] == 'B':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]
        ans += dp[i]

print(ans)


Measured memory_bytes: 11236
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

int ans=0;
int deep=0;
int n;

void dfs(int np){
  if(deep==9){
    string s=to_string(np);
    set<int> st;
    for(int i=0;i<s.size();i++)st.insert(s[i]);
    if(st.size()==3&&np<=n)ans++;
  }else{
    deep++;
    if(np==0)dfs(0);
    dfs(np*10+3);
    dfs(np*10+5);
    dfs(np*10+7);
    deep--;
  }
}

signed main(){
  cin>>n;
  dfs(0);
  cout<<ans<<endl;
}


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

int countAB(string s){
    int ret = 0;
    rep(i, s.size()-1){
        if(s[i]=='A' && s[i+1]=='B') ++ret;
    }
    return ret;
}

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

    int n;
    cin >> n;

    vector<string> s(n);
    int res = 0;
    int frontB = 0;
    int backA = 0;
    int both = 0;
    rep(i, n){
        cin >> s[i];
        res += countAB(s[i]);
        if(s[i].front() == 'B' && s[i].back() == 'A') ++both;
        if(s[i].front() == 'B') ++frontB;
        if(s[i].back() == 'A') ++backA;
    }
    res += min(frontB, backA);
    if(frontB != 0 && frontB==backA && backA==both) --res;

    cout << res  << endl;

    return 0;
}

Measured memory_bytes: 3672
n, k = map(int, input().split())
p = list(map(lambda x: (1+int(x))/2, input().split()))
s = sum(p[0:k])
ans = s
for i in range(k, n):
    s += p[i] - p[i-k]
    ans = max(ans, s)
print(ans)

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

int main()
{
    int n, m;
    cin >> n >> m;
    unordered_map<int, int> counter;
    rep(i, 2 * m)
    {
        int a;
        cin >> a;
        counter[a]++;
    }
    bool flag = true;
    for (auto p : counter)
    {
        if (p.second & 1)
            flag = false;
    }
    cout << (flag ? "YES\n" : "NO\n");
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007LL;

ll ipow(ll base, ll exp)
{
    ll result = 1LL;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}

struct DisjointSet {
    vector<int> parent, rank, size;
    DisjointSet(int n) : parent(n), rank(n, 1), size(n, 1) {
        for(int i = 0; i < n; ++i) 
            parent[i] = i;
    }

    int find(int u) {
        if(u == parent[u]) return u;
        return parent[u] = find(parent[u]);
    }

    void merge(int u, int v) {
        u = find(u); v = find(v);
        if(u == v) return;
        if(rank[u] > rank[v]) swap(u, v);
        parent[u] = v;
        if(rank[u] == rank[v]) ++rank[v];
        size[v] += size[u];
    }
};

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
ll L, R;
const ll M = 2019LL;

int main(void) {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    cin >> L >> R;

    set<ll> s;
    ll limit = min(5000LL, R-L);
    for(ll i=L; i<=L+limit; ++i) {
        for(ll j=i+1; j<=L+limit; ++j) {
            s.insert((i*j)%M);
        }
    }
    cout << *s.begin() << endl;
    return 0;
}


Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


# 二次元累積和
class Ruiwa():
    def __init__(self, a):
        self.H = h = len(a)
        self.W = w = len(a[0])
        self.R = r = a
        for i in range(h):
            for j in range(1,w):
                r[i][j] += r[i][j-1]

        for i in range(1,h):
            for j in range(w):
                r[i][j] += r[i-1][j]

    def search(self, x1, y1, x2, y2):
        if x1 > x2 or y1 > y2:
            return 0

        r = self.R
        rr = r[y2][x2]
        if x1 > 0 and y1 > 0:
            return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
        if x1 > 0:
            rr -= r[y2][x1-1]
        if y1 > 0:
            rr -= r[y1-1][x2]

        return rr

def main():
    rr = []

    def f(n):
        a = [LI() for _ in range(n)]
        xs = set()
        ys = set()
        for l,t,r,b in a:
            xs.add(l)
            xs.add(r)
            ys.add(t)
            ys.add(b)
        xd = {}
        for x,i in zip(sorted(xs), range(len(xs))):
            xd[x] = i
        yd = {}
        for y,i in zip(sorted(ys), range(len(ys))):
            yd[y] = i
        z = []
        for l,t,r,b in a:
            z.append([xd[l],yd[t],xd[r],yd[b]])
        xx = len(xs) + 3
        yy = len(ys) + 3
        aa = [[0]*xx for _ in range(yy)]
        ii = [2**i for i in range(n)]
        for i in range(n):
            l,t,r,b = map(lambda x: x+1, z[i])
            aa[b][l] += ii[i]
            aa[t][l] -= ii[i]
            aa[b][r] -= ii[i]
            aa[t][r] += ii[i]
        rui = Ruiwa(aa)
        t = rui.R
        def _f(i,j,k):
            if i < 0 or i >= yy or j < 0 or j >= xx:
                return
            if t[i][j] != k:
                return
            t[i][j] = -1
            for di,dj in dd:
                _f(i+di,j+dj,k)
        r = 0
        for i in range(yy):
            for j in range(xx):
                if t[i][j] >= 0:
                    _f(i,j,t[i][j])
                    r += 1
        return r

    while True:
        n = I()
        if n == 0:
            break
        rr.append(f(n))

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 22556
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) throws Exception {		
		
		ArrayList<Long> ks = new ArrayList<>();
		
		double min = Long.MAX_VALUE;
		long dif = 10000000;
		for(long x = 999999999999999L; x >= 1; x -= dif){
			double c = f(x);
			if(c <= min){
				ks.add(x);
				min = c;
			}
			int s = (int)Math.log10(x);
			dif = (long)Math.pow(10, 2*s/3);
		}
		Collections.reverse(ks);
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		for(int i = 0; i < n; i++){
			System.out.println(ks.get(i));
		}
	}
	static double f(long x){
		long aux = x; int sum = 0;
		while(aux > 0){
			sum += aux%10;
			aux/=10;
		}
		return x*1.0 / sum;
	}
}


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

using namespace std;

int dp[50][500][500];

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

  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int a = 0; a <= 400; a++) {
      for (int b = 0; b <= 400; b++) {
        if (dp[i][a][b] == -1) continue;
        if (dp[i + 1][a][b] == -1) {
          dp[i + 1][a][b] = dp[i][a][b];
        } else {
          dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b]);
        }
        if (dp[i + 1][a + A[i]][b + B[i]] == -1) {
          dp[i + 1][a + A[i]][b + B[i]] = dp[i][a][b] + C[i];
        } else {
          dp[i + 1][a + A[i]][b + B[i]] =
              min(dp[i + 1][a + A[i]][b + B[i]], dp[i][a][b] + C[i]);
        }
      }
    }
  }

  int result = 1e9;
  for (int k = 1; k < 1000; k++) {
    if (MA * k > 400 or MB * k > 400) break;

    if (dp[N][MA * k][MB * k] != -1) {
      result = min(result, dp[N][MA * k][MB * k]);
    }
  }
  if (result == 1e9) {
    result = -1;
  }
  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 49024
import itertools


def main():
    n, m = map(int, input().split())

    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    x_len = 0
    y_len = 0

    for i in range(n):
        x_len += (2 * i - n + 1) * x[i] % (10 ** 9 + 7)
        # print(x_len)

    for j in range(m):
        y_len += (2 * j - m + 1) * y[j] % (10 ** 9 + 7)
        # print(y_len)

    print(x_len * y_len % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 18392
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll w,a,b;
    cin >> w >> a >> b;
    if(b > a){
      print(max(0LL, b - a - w));
    } else {
      print(max(0LL, a - b - w));
    }

}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read()[0];
    let a: Vec<i64> = read();
    let mut b: Vec<i64> = a.iter().enumerate().map(|(i, &x)| x - i as i64).collect();
    b.sort();
    let mid = (b[(n - 1) / 2] + b[n / 2]) / 2;
    let ans = b.iter().fold(0_i64, |sum, &x| sum + (x - mid).abs());
    println!("{}", ans);
}


Measured memory_bytes: 10492
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const double INF=pow(10,14);
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// グローバルに持っていく
using Graph = vector<vector<int>>;

int main(){
    ll N;
    ll xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    cin>>N;
    Graph G(N+2);
    vector<vector<double>> cost(N+2,vector<double>(N+2,-1));
    vector<ll> x(N+2),y(N+2),r(N+2,0);
    x[0]=xs;
    y[0]=ys;
    x[N+1]=xt;
    y[N+1]=yt;
    
    REP(i,N){
        cin>>x[i+1]>>y[i+1]>>r[i+1];
        x[i+1];
        y[i+1];
    }

    REP(i,N+1){
        REP2(j,i+1,N+2){
            G[i].push_back(j);
            G[j].push_back(i);
            double d=max(0.0,sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-(r[i]+r[j]));
            cost[i][j]=d;
            cost[j][i]=d;
        }
    }

    //ダイクストラ
    vector<double> dist(N+2,INF);
    priority_queue<pair<double,ll>,vector<pair<double,ll>>,greater<pair<double,ll>>> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(make_pair(0,0)); // 0 を橙色頂点にする
    
        // 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        
        pair<double,ll> p = que.top(); // 優先度キューから先頭頂点を取り出す
        que.pop();
        double d=p.first;
        ll v=p.second;
        if(dist[v]<d) continue;

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            
            if (cost[v][nv] == -1) continue; // 行けない行き先ならパス
            double nd=d+cost[v][nv];
            // 新たな頂点 nv について距離が短いなら更新
            if(nd<dist[nv]){
                
                dist[nv] = nd;
                que.push(make_pair(nd,nv));
            }
        }
    }
    printf("%.10f\n",dist[N+1]);

}

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

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

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

    sort(A.begin(), A.end());

    int total = 0;
    for(int i = n - 1; i >= 0; i--){
        if(i == n - 1){
            total += A[i] / 2;
        }else{
            total += A[i];
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
#define max(p,q)((p)>(q)?(p):(q))

ll a[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	ll ans=0;
	for(int d=1;d*2<n-1;d++){
		int s=0,g=n-1;
		ll crr=0;
		while(1){
			int ns=s+d;
			int ng=g-d;
			if(ng<=d||ns==ng||ns==g)break;
			s=ns;
			g=ng;
			crr+=a[s]+a[g];
			ans=max(ans,crr);
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int> 
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << " - " << x << endl;
const ll MOD = 1e9 + 7;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;
using namespace std;

int vis[100002];
vector<int>adj[100002];

void dfs(int node){
    vis[node]=1;
    for(auto child:adj[node]){
        if(!vis[child]){
            dfs(child);
        }
    }
}

int main(){
    IOS;
    int n,m; cin>>n>>m;
    int a,b,c;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());

// /mnt/c/Users/vince/Desktop/POST-IOI/  


struct dat
{
	long base;
	long val;
	dat() { base = 0, val = 0; }
};

const long MOD = 998244353;
int n, q;
long pw10[200003];
int lazy[1000003];
dat tree[1000003];

dat merge(dat a, dat b)
{
	dat res;
	res.base = (a.base+b.base)%MOD;
	res.val = (a.val+b.val)%MOD;
    return res;
}

void build(int pos, int kir, int kan)
{
	if(kir == kan)
	{
		// printf("%d %d %d\n", pos, kir, pw10[n-kir]);
		tree[pos].base = pw10[n-kir];
		tree[pos].val = pw10[n-kir];
		return;
	}
	int mid = (kir+kan)/2;
	build(pos*2, kir, mid);
	build(pos*2+1, mid+1, kan);
	tree[pos] = merge(tree[pos*2], tree[pos*2+1]);
}

void ceklazy(int pos, int kir, int kan)
{
	if(lazy[pos])
	{
		tree[pos].val = (1LL*lazy[pos]*tree[pos].base)%MOD;
		if(kir != kan)
		{
			lazy[pos*2] = lazy[pos];
			lazy[pos*2+1] = lazy[pos];
		}
		lazy[pos] = 0;
	}
}

void update(int pos, int kir, int kan, int qkir, int qkan, int val)
{
	ceklazy(pos, kir, kan);
	if(qkir <= kir && kan <= qkan)
	{
		lazy[pos] = val;
		ceklazy(pos, kir, kan);
		return;
	}
	if(qkan < kir || kan < qkir) return;

	int mid = (kir+kan)/2;
	update(pos*2, kir, mid, qkir, qkan, val);
	update(pos*2+1, mid+1, kan, qkir, qkan, val); 
	tree[pos] = merge(tree[pos*2], tree[pos*2+1]);
}

dat query(int pos, int kir, int kan, int qkir, int qkan)
{
	ceklazy(pos, kir, kan);
	if(qkir <= kir && kan <= qkan) return tree[pos];
	if(qkan < kir || kan < qkir) return dat();

	int mid = (kir+kan)/2;
	dat a = query(pos*2, kir, mid, qkir, qkan);
	dat b = query(pos*2+1, mid+1, kan, qkir, qkan);
	return merge(a, b);
}

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	pw10[0] = 1;
	for(int i = 1; i <= 200000; i++)
		pw10[i] = (pw10[i-1]*10LL)%MOD;

	scanf("%d %d", &n, &q);


	build(1, 1, n);
	while(q--)
	{
		int l, r, d;
		scanf("%d %d %d", &l, &r, &d);
		update(1, 1, n, l, r, d);
		printf("%lld\n", tree[1].val);
	}
}






Measured memory_bytes: 23060
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int vs[200000+10];
ll hs[200000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    hs[vs[i]]++;
  }
  ll total = 0;
  REP(i, n) {
    total += hs[i+1] * (hs[i+1]-1) / 2;
  }
  REP(i, n) {
    int v = vs[i];
    ll h = hs[v];
    total -= h * (h-1) / 2;
    --h;
    total += h * (h-1) / 2;
    printf("%lld\n", total);
    total -= h * (h-1) / 2;
    ++h;
    total += h * (h-1) / 2;
  }
  return 0;
}


Measured memory_bytes: 5528
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long

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

  int flag = 0;
  for(int i = 0; i < k; i++) {
    //cout << a << " " << b << endl;
    if(flag == 0) {
      if(a % 2 != 0) {
        a--;
        if(a <= 0) {
          a = 0;
        }

      }
      b += a/2;
      a = a/2;
      flag = 1;
    }
    else if(flag == 1) {
      if(b % 2 != 0) {
        b--;
        if(b <= 0) {
          b = 0;
        }

      }
      a += b/2;
      b = b/2;
      flag = 0;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int p,q,r;
  cin>>p>>q>>r;
  int ans=min(p+q, p+r);
  ans=min(ans, q+r);
  cout<<ans<<endl;
  
  
 
}

Measured memory_bytes: 256