akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int comp(const void* a, const void* b) {
  return *(int*)a - *(int*)b;
}

int main(void) {
  int n, i;
  int* d;
  scanf("%d", &n);
  d = (int*)malloc(n*sizeof(int));
  for(i=0; i<n; i++) {
    scanf("%d", &d[i]);
  }
  qsort(d, n, sizeof(int), comp);
  printf("%d\n", d[n/2]-d[n/2-1]);
  return 0;
}


Measured memory_bytes: 892
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    B=list(map(int,input().split()))
    ans=B[0]+B[-1]
    for i in range(n-2):
        ans+=min(B[i],B[i+1])

    print(ans)
resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d) {
    cout << "Yes" << endl;
  } else if ((abs(a - b) <= d) && (abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
 
}

Measured memory_bytes: 256
# coding: utf-8

def isValid(target:str):
    if target[0] != "A":
        return False
    if target.count("A") != 1:
        return False
    if target.count("C") != 1:
        return False
    if target[2:len(target)-1].count("C") != 1:
        return False
    for i in target:
        if i == "A":
            continue
        if i == "C":
            continue
        if "a" <= i <= "z":
            continue
        return False
    return True

if isValid(input().rstrip()):
    print("AC")
else:
    print("WA")

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

int main(){
    int N; cin >> N;
    int a[N];
    int count4 = 0, count2 = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] % 4 == 0) count4++;
        else if(a[i] % 2 == 0) count2++;
    }
    int Odd = N - count4 - count2;
    // N = N - count2/2;
    Odd += count2%2;
    if(count4 >= Odd - 1 ) cout << "Yes" << endl;
    else cout << "No" << endl;

    
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

namespace PANASONIC2020
{
    class A
    {
        static void Main(string[] args)
        {
            //var a = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
            var a = new int[32] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
            var K = int.Parse(Console.ReadLine());
            Console.WriteLine(a[K - 1]);
        }
    }
}


Measured memory_bytes: 11092
import bisect

N,D,A = map(int,input().split())

monsters = []
for i in range(N):
    X, H =map(int,input().split())
    monsters.append([X,H])

monsters = sorted(monsters)

id = 0
ans = 0

damage = [0 for i in range(N)]

while id < N:
    if id > 0: damage[id] += damage[id-1]
    nowX, nowH = monsters[id][0], monsters[id][1]
    nowH -= damage[id]

    if nowH > 0:
        damage[id] += A * ((nowH + A - 1) // A)

        right = bisect.bisect_left(monsters, [nowX+2*D+1,0])
        if right < N:
            damage[right] -= A * ((nowH + A - 1) // A)

        ans += (nowH + A -1) // A

    id += 1

print(ans)

Measured memory_bytes: 44164
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

x,y = map(int,input().split())
a = math.gcd(x,y)
print(a)


Measured memory_bytes: 6356
import numpy as np

N, M = tuple(map(int, input().split()))
Ls = np.zeros((M,), dtype=int)
Rs = np.zeros((M,), dtype=int)
Ds = np.zeros((M,), dtype=int)

for i in range(M):
    Ls[i], Rs[i], Ds[i] = tuple(map(int, input().split()))

# debug 1 exit()

Ls = Ls - 1
Rs = Rs - 1

adjacency_list = []
for i in range(N):
    adjacency_list.append([])

for i in range(M):
    adjacency_list[Ls[i]].append((Rs[i], Ds[i]))
    adjacency_list[Rs[i]].append((Ls[i], -Ds[i]))

# print(adjacency_list)

# BFSする
visited = np.zeros(N, dtype=bool)
weights = np.zeros(N, dtype=int)
to_be_visited = []

# debug 2 exit()
pointer = 0
for pointer in range(N):
    if not visited[pointer]:
        to_be_visited.append(pointer)
        while len(to_be_visited) != 0:
            node_index = to_be_visited.pop()
            candidate = adjacency_list[node_index]
            for _i, weight in candidate:
                if not visited[_i]:
                    visited[_i] = True
                    weights[_i] = weights[node_index] + weight
                    to_be_visited.append(_i)

for i in range(M):
    # print("given weights: {}, estimated weights: {}".format(Ds[i],weights[Rs[i]]-weights[Ls[i]]))
    if weights[Rs[i]] - weights[Ls[i]] == Ds[i]:
        # print("passed {} th condition".format(i))
        pass
    else:
        # print("failed {} th condition".format(i))
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 81840
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define red(i,a,b) for(int i=(a);i>=(b);i--)
#define db double
#define ld long db
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=15;
int n,m,cant[N];
signed main(){
//	freopen("a","r",stdin);
	n=read(),m=read();rep(i,1,m){int x=read();cant[x]=1;}
	while(true){
		int flag=0,x=n;
		while(x)flag|=(cant[x%10]),x/=10;
		if(!flag)return cout<<n,signed();
		n++;
	}
}

Measured memory_bytes: 3592
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int W = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        // 左をA,右をBとする
        int rightSideOfRectangleA = a + W;
        int leftSideOfRectangleA = a;
        int rightSideOfRectangleB = b + W;
        int leftSideOfRectangleB = b;
        int difference = 0;
        if(a > b){
             difference = leftSideOfRectangleA - rightSideOfRectangleB;
        }else{
            difference = leftSideOfRectangleB - rightSideOfRectangleA;
        }
        if(difference < 0) difference = 0;
        System.out.println(difference);


    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll n;
vll a, esum, osum, sum;

bool lt(ll x, ll ai, ll bi) {
  if (bi<0 || bi>=n) return true;
  if (ai<0 || ai>=n) return false;
  ll d1 = abs(x-a[ai]);
  ll d2 = abs(x-a[bi]);
  if (d1 < d2) return true;
  if (d1 == d2) return ai<bi;
  return false;
}

ll calc(ll r, ll d) {
  if (r<0) return 0;
  if (d==0) return esum[r];
  else if (d==1) return osum[r];
  else return sum[r];
}

ll calc(ll l, ll r, ll d) {
  if (l>r) return 0;
  return calc(r, d) - calc(l-1, d);
}

ll query(ll x) {
  ll lb=1, ub=n+1;
  while(ub-lb>1) {
    ll mid = (lb+ub) / 2;
    ll ai = mid / 2;
    ll bi = mid / 2;
    if (ai + bi < mid) ai++;
    ll l = n - mid;
    ll r = n - ai - 1;
    if (lt(x, r+1, l)) ub = mid;
    else lb = mid;
  }
  ll ai = (lb+1)/2;
  ll d = n % 2;
  ll ans = calc(0, n-lb-1, d) + calc(n-lb, n-ai-1, -1);
  return sum[n-1] - ans;
}

int main() {
  ll q; cin >> n >> q;
  a.resize(n), esum.resize(n), osum.resize(n), sum.resize(n);
  REP(i, n) cin >> a[i];
  sum[0] = a[0];
  rep(i, 1, n) sum[i] = sum[i-1] + a[i];
  esum[0] = a[0];
  rep(i, 1, n) esum[i] = esum[i-1] + (i%2==0? a[i]: 0);
  osum[0] = 0;
  rep(i, 1, n) osum[i] = osum[i-1] + (i%2==1? a[i]: 0);
  REP(_, q) {
    ll x; cin >> x;
    ll ans = query(x);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4864
import heapq

N = int(input())

A = list(map(int, input().split()))

left = A[:N]
left_total = [(sum(left))]
heapq.heapify(left)

for i in range(N, 2*N):
    l = heapq.heappop(left)
    # 入れ替える場合
    if l < A[i]:
        heapq.heappush(left,A[i])
        left_total.append(left_total[-1] - l + A[i])
    # Aのある要素よりleftの最小要素の方が大きいので入れ替えない
    else:
        heapq.heappush(left,l)
        left_total.append(left_total[-1])
        

#rightもN要素から始めるが、leftとの対応のために最後にtotalをひっくり返すのを忘れない
right = [-i for i in A[2 * N:]]
right_total = [sum(right)]
heapq.heapify(right)

for i in reversed(range(N, 2*N)):
    r = heapq.heappop(right)
    if r < -A[i]:
        heapq.heappush(right, -A[i])
        right_total.append(right_total[-1] - r - A[i])
    # rの最小値の方がちいさいのでそのまま
    else:
        heapq.heappush(right, r)
        right_total.append(right_total[-1])


# left_totalとの対応のために逆にする
right_total = right_total[::-1]

ans = -float("inf")
for i in range(len(left_total)):
    ans = max(ans, left_total[i] + right_total[i])

print(ans)

Measured memory_bytes: 37212
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
 
int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
 
    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;
 
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3624
read x
if((x==2))
then
    echo 2
    exit
elif((x%2==0))
then
    x=$((x+1))
fi
for i in `seq $x 2 100003`
do
    l=`echo $i | factor | tr ' ' '\n' | wc -l`
    if((l==2))
    then
        echo $i
        exit
    fi
done

Measured memory_bytes: 6424
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<vector<int>> G(100010, vector<int>());

void dfs(int f, vector<int> &froms){
	for(auto t:G[f]){
		if(froms[t] == inf){
			froms[t] = f;
			dfs(t, froms);
		}
	}
}

void dfs2(int f, int c, vector<int> &color){
	for(auto t:G[f]){
		if(color[t] == inf){
			color[t] = c;
			dfs2(t, c, color);
		}
	}
}

int main(){
	int N, a, b;
	cin >> N;
	G.resize(N);
	rep(i,N-1){
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> froms(N, inf);
	froms[0] = -1;
	dfs(0, froms);
	vector<int> dir;
	dir.push_back(N-1);
	int k = N-1;
	while(true){
		if(froms[k] == -1)break;
		dir.push_back(froms[k]);
		k = froms[k];
	}
	reverse(all(dir));
	int pos = (dir.size()-1)/2;
	int bst = dir[pos], wst = dir[pos+1];
	vector<int> color(N,inf);
	color[bst] = 0; color[wst] = 1;
 	dfs2(bst, 0, color); dfs2(wst, 1, color);
	int bcnt = 0, wcnt = 0;
	rep(i,N)((color[i] == 0) ? ++bcnt : ++wcnt);
	cout << ((bcnt > wcnt) ? "Fennec" : "Snuke") << endl;
	return 0;
}


Measured memory_bytes: 14604
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{

  i64 n;
  cin >> n;
  vector<i64> edge[n], c(n);
  for (i64 i = 0; i < n - 1; i++)
  {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for (i64 i = 0; i < n; i++)
    cin >> c[i];
  sort(c.begin(), c.end(), greater<i64>());
  i64 sum = 0, now = 1;
  vector<i64> ans(n, -1);
  queue<i64> que;
  que.push(0);
  ans[0] = c[0];
  while (que.size())
  {
    i64 p = que.front();
    que.pop();
    for (i64 i : edge[p])
      if (ans[i] == -1)
      {
        ans[i] = c[now];
        sum += c[now];
        now++;
        que.push(i);
      }
  }
  cout << sum << endl;
  for (i64 i = 0; i < n; i++)
    cout << ans[i] << (i + 1 == n ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>

#include <vector>
#include <string>
#include <iterator>
#include <algorithm>

typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

using namespace std;

// change min/max
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; }

template<class T> void output(std::vector<T> & A) {
    const int n = A.size();
    for (int i = 0; i < n - 1; ++i) {
        std::cout << A[i] << " ";
    }
    std::cout << A[n - 1] << std::endl;
}

#define MAX 100001
const int NIL = -1;
struct Node { int parent=NIL, left = NIL, right = NIL; };
Node node[MAX];

int getDepth(int nodeIdx, const int n) {
    int cnt = 0;
    int pnb = node[nodeIdx].parent;
    while (pnb != NIL) {
        pnb = node[pnb].parent;
        ++cnt;
    }
    return cnt;
}

void printRes(const int n, vector<int>& depth) {
    rep(i, n) {
        cout << "node " << i << ": parent = " << node[i].parent << ", depth = " << depth[i];
        
        // root/leaf/internal
        string s;
        if (node[i].parent == NIL)    s = ", root, ";
        else if (node[i].left == NIL) s = ", leaf, ";
        else s = ", internal node, ";
        cout << s;

        // children
        cout << "[";
        int idxCh = node[i].left;
        for (int i = 0; ; ++i) {
            if (idxCh == NIL) break;
            if (i != 0) cout << ", ";
            cout << idxCh;
            idxCh = node[idxCh].right;
        }
        cout << "]" << endl;
    }
}

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

    int n; cin >> n;

    rep(i, n) {
        int idxNode; cin >> idxNode;
        int nbCh; cin >> nbCh;

        // no children
        if (nbCh == 0) continue;
        
        // chlidren
        vector<int> children(nbCh);
        rep(j, nbCh) {
            cin >> children[j];
            node[children[j]].parent = idxNode;
        }

        // left child
        node[idxNode].left = children[0];

        // sibling
        rep(j, nbCh - 1) {
            node[children[j]].right = children[j + 1];
        }        
    }

    vector<int> depth(n, 0);
    rep(i, n) depth[i] = getDepth(i, n);
    printRes(n, depth);

    return 0;
}



Measured memory_bytes: 4708
#include <iostream>
using namespace std;

int H, A[5000000];

int left(int i)
{
	return i * 2;
}

int right(int i)
{
	return i * 2 + 1;
}

void maxHeapify(int i)
{
	int l, r, largest;
	l = left(i);
	r = right(i);

	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;

	if (r <= H && A[r] > A[largest]) largest = r;

	if (largest != i) 
	{
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int main(void)
{
	cin >> H;

	for (int i = 1; i <= H; i++) cin >> A[i];
	for (int i = H / 2; i >= 1; i--) maxHeapify(i);
	for (int i = 1; i <= H; i++) cout << " " << A[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 5020
/*
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
*/
//
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
void solve()
{
    int n;
    cin>>n;
    vector<int> v(n);
    int cnt=0;
    f(i,n)
    {
        cin>>v[i];
    }
    int k,x;
    cin>>k>>x;
    vector<int> a;
    f(i,n)
    {
        a.pb((v[i]^x)-v[i]);
        if(a.back()>=0)
        {
            cnt++;
        }
    }
    sort(all(a),greater<int>());
    if(cnt>=k)
    {
        int i=0;
        ll sum=0;
        while(i<n&&a[i]>=0)
        {
            sum=sum+a[i];
            i++;
        }
        if(cnt%k&&cnt%2)
        {
            if(i>=0)
            {
                if(abs(v[i+1])<abs(v[i]))
                {
                    sum=sum-a[i+1];
                }
                else
                {
                    sum=sum+a[i];
                }
                sum=accumulate(all(v),sum);
                cout<<sum<<endl;
            }
            else
            {
                sum=sum-a[i+1];
                sum=accumulate(all(v),sum);
                cout<<sum<<endl;
            }
        }
        else
        {
            sum=accumulate(all(v),sum);
            cout<<sum<<endl;
        }
    }
    else
    {
        
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //let's fuck dp
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    int temp=0;
    if(x==w/2.0&&y==h/2.0)
    {
      temp=1;
    }
    cout<<(w*h)/2.0<<" "<<temp<<endl;
}

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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  string s;
  ll k;
  cin >> s >> k;
  int cnt = 0;
  for(auto x : s){
    if(x != '1'){
      cout << x << endl;
      return 0;
    }
    cnt++;
    if(cnt == k){
      cout << '1' << endl;
      return 0;
    }  
  }
  
   
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

struct FordFulkerson {
    typedef long long flow_type;
    struct edge {
        int src, dst;
        flow_type capacity, flow;
        size_t rev;
    };
    int n;
    vector<vector<edge>> adj;
    FordFulkerson(int n) : n(n), adj(n) { }
    void add_edge(int src, int dst, flow_type capacity) {
        adj[src].push_back({src, dst, capacity, 0, adj[dst].size()});
        adj[dst].push_back({dst, src, capacity, 0, adj[src].size()-1});
    }
    flow_type max_flow(int s, int t) {
        vector<bool> visited(n);
        function<flow_type(int,flow_type)> augment = [&](int u, flow_type cur) {
            if (u == t) return cur;
            visited[u] = true;
            for (auto &e: adj[u]) {
                if (!visited[e.dst] && e.capacity > e.flow) {
                    flow_type f = augment(e.dst, min(e.capacity - e.flow, cur));
                    if (f > 0) {
                        e.flow += f;
                        adj[e.dst][e.rev].flow -= f;
                        return f;
                    }
                }
            }
            return flow_type(0);
        };
        for (int u = 0; u < n; ++u)
            for (auto &e: adj[u]) e.flow = 0;

        flow_type flow = 0;
        while (1) {
            fill(visited.begin(),visited.end(), false);
            flow_type f = augment(s, INF);
            if (f == 0) break;
            flow += f;
        }
        return flow;
    }
};


int main(){
  int H,W;cin >> H >>W;
  FordFulkerson g(2+H+W);
  vector<string> a(H);
  repeat(i,H)cin >> a[i];
  repeat(i,H){
    repeat(j,W){
      if(a[i][j] == 'o'){
        g.add_edge(i+1,H+j+1,1);
      }else if(a[i][j] == 'S'){
        g.add_edge(0,i+1,INF);
        g.add_edge(0,H+j+1,INF);
      }else if(a[i][j] == 'T'){
        g.add_edge(i+1,H+W+1,INF);
        g.add_edge(H+j+1,H+W+1,INF);
      }
    }
  }
  ll ans = g.max_flow(0,H+W+1);
  if(ans>=INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        int[] c = new int[M];
        int[] d = new int[M];
        for (int i = 0; i < M; ++i) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        for (int i = 0; i < N; ++i) {
            int minIdx = -1;
            long min = Long.MAX_VALUE;
            for (int j = 0; j < M; ++j) {
                long dist = mdist(a[i], b[i], c[j], d[j]);
                if (dist < min) {
                    min = dist;
                    minIdx = j;
                }
            }
            _out.println(minIdx + 1);
        }
    }
    private long mdist(int x1, int y1, int x2, int y2) {
        return Math.abs(x2 - x1) + Math.abs(y2 - y1);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

int A,B,C,D;
const int mod = 998244353;

int pd[3100][3100];

int rec(int x, int y) {
    if (x < A || y < B) return 0;
    if (x == A && y == B) return 1;

    int &ret = pd[x][y];
    if (ret == -1) {
        ret = 0;

        // x y painted
        ret = (rec(x-1, y) + rec(x, y-1)) % mod;
        
        // x y not selected
        long long th = 0;
        long long xy = ( (x-1) * 1ll * (y-1)) % mod;
        th = (rec(x-1, y) * 1ll * (y-1)) % mod;
        th = (th + rec(x, y-1) * 1ll * (x-1)) % mod;
        th = (th - rec(x-1,y-1) * 1ll * xy) % mod;

        th = (th + mod) % mod;
        ret = (ret + th) % mod;
    }

    return ret;
}

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

    memset(pd,-1,sizeof(pd));
    cin >> A >> B >> C >> D;

    cout << rec(C, D) << endl;
}

Measured memory_bytes: 41480
# Author: cr4zjh0bp
# Created: Sun Mar 22 11:54:41 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()
n = len(s)
flag = True
for i in range((n - 1) // 2):
    p = (n - 1) // 2
    if s[i] != s[p - i - 1]:
        flag = False

for i in range((n + 3) // 2 - 1, n):
    p = n
    if s[i] != s[p - i - 1]:
        flag = False

print("Yes" if flag else "No")

Measured memory_bytes: 3064
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P1 = sorted(P)
A = []
for x in itertools.permutations(P1):
	A.append(x)

a, b = 0, 0
for i in range(len(A)):
	if P == list(A[i]):
		a = i
	if Q == list(A[i]):
		b = i

print(abs(a-b))

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

int main() {
 int sum = 0;
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
  int l, r;
    cin >> l >> r;
    sum += 1 + r - l;
  }
  cout << sum;
}


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

void lcs(string s1,string s2){
	int n1 = s1.length();
  	int n2 = s2.length();
  	int dp[n1+1][n2+1];
  	string res;
  	for(int i=0;i<=n1;i++){
    	for(int j=0;j<=n2;j++){
        	if(i==0 || j==0)
              dp[i][j]=0;
          	else if(s1[i-1]==s2[j-1]){
            	dp[i][j]=dp[i-1][j-1]+1;
            }
          	else 
              	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
  	if(dp[n1][n2]==0)
      cout<<"";
  	else{
      	int i=n1;
      	int j=n2;
        while(i>0 && j>0){
            if(s1[i-1]==s2[j-1]){
            	res.push_back(s2[j-1]);
              	i--;
              	j--;
            }
          	else if(dp[i][j-1]>dp[i-1][j])
              	j--;
          	else 
              	i--;
    	}
      	reverse(res.begin(),res.end());
      	
        cout<<res;
    }
}

int main(){
	string s1,s2;
  	cin>>s1;
  	cin>>s2;
  	
  	lcs(s1,s2);
}

Measured memory_bytes: 38820
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int ans = 0;
        for (int a = 1; a <= N; a++) {
            ans += N / a;
            if (N % a == 0) ans--;
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32812
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int a = ni();
		int b = ni();
		int na = n*a;
		if(na < b) {
			System.out.println(na);
		}else {
			System.out.println(b);
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);   
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int j = 0; j < N; j++){
    if(j % 2 == 0){
      A += vec.at(j);
    }
    else{
      B += vec.at(j);
    }  
  }
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    char c; cin >> c;

    if('A' <= c && c <= 'Z'){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }
    

}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {

  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, r = s.size() - 1;

  int ans = 0;
  while (l <= r) {
    if (s[l] == 'R')
      ++l;
    else if (s[r] == 'W')
      --r;
    else {
      ++ans;
      swap(s[l], s[r]);
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3768
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
int k,n;
int a[100000000];

int main(){
  scanf("%d%d",&k,&n);
  int max=0;
  int cou=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(max<a[i])
    { cou=i;
      max=a[i];
    }
  }
  int tmp=0;
  rep(i,n){
    if(i!=cou)
    {
      tmp+=a[i];
    }
  }
  if(tmp>=max){ printf("0\n");
  }else{
    printf("%d\n",max-tmp-1);
  }

  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		public long[] readLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static final FS sc = new FS();
	static final PrintWriter out = new PrintWriter(System.out);
	static final int mod = 1000000007;

	public static void main(String[] args) {
		solve();
		out.close();
	}

	static void solve() {
		int t = sc.nextInt(), x = sc.nextInt();
		double ans = (double)t / (double)x ;
		System.out.format("%.10f", ans);
		
		

	}
}


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

int main() {
 int n,m,x;
 cin >> n >> m >> x;
 int a = 0, b = 0;
 rep(i,m){
   int y;
   cin >> y;
   if(y < x) a++;
   else b++;
 }
 cout << min(a,b) << endl;
 
 } 

Measured memory_bytes: 3604
#include<stdio.h>
#define INFTY 500000

int min(int,int);


int main(){
  int n;
  int i,j,l,p[101],m[101][101],k,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }
  
      
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
    for(l=2;l<=n;l++){
      for(i=1;i<=n-l+1;i++){
	j=i+l-1;
	m[i][j]=INFTY;
      
    
    for(k=i;k<=j-1;k++){
      q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      m[i][j]=min(m[i][j],q);
    }
  }
}
    printf("%d\n",m[1][n]);
    return 0;
}

int min(int a,int b){
  if(a<b)return a;
  else if(a>b)return b;
  else if(a==b)return a;
  
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define maxl 300010
using namespace std;

int n,m,ans;
int a[maxl];
char s[maxl];

inline void prework()
{
	
}

inline void mainwork()
{
	
}

inline void print()
{
	int x,y;
	for(int i=1;i<=3;i++)
		a[i]=(4-i)*100000;
	scanf("%d %d",&x,&y);
	int ans=a[x]+a[y];
	if(x==1 && y==1)
		ans+=100000*4;
	printf("%d",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

Measured memory_bytes: 256
#include<queue>
#include <iostream>
#include <string>
#include<map>
using namespace std;
int main()
{
    string s;
    int n,a;
    cin>>n>>s;
    for(int i=0;i<s.size();i++)
    {
       if(s[i]+n>'Z')
       {a=n-('Z'-s[i]);
       a--;
        s[i]=a+'A';
        cout<<s[i];
        continue;
       }
       s[i]+=n;
        cout<<s[i];
    }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>

using namespace std;
int main()
{
    /*
    int N, K, M, tmpA, allA = 0;
    int ans;
    cin >> N;
    cin >> K;
    cin >> M;
    */

    ///vector<int> A(N);

    int N, count=0;
    string S;
    cin >> N;
    cin >> S;

    for (int i = 0; i < N-2; i++)
    {
        if (S.substr(i,3) == "ABC")
        {
            count++;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
using namespace std;



int main(){
    int N;
    cin >> N;
    int64 things[N], prefixSum[N];
    int64 total = 0;
    for (size_t i = 0; i < N; i++)
    {   
        prefixSum[i] = (total % 1000000007);
        cin >> things[i];
        things[i] %= 1000000007;
        total += (things[i] % 1000000007);
    }
    total = 0;
    for(int i = N-1; i > 0; i--){
        int64 tmpt = (things[i] * (prefixSum[i]%1000000007));
        total += tmpt%1000000007;
    }
    cout << total%1000000007;
}

Measured memory_bytes: 6736
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <numeric>
using namespace std;

long long int gcd(int a, int b){
  return b ? gcd(b,a%b) : a;
}

int main()
{
  int N;
  cin >> N;
  long long int A[N], L[N], R[N];
  long long int ans = 0;
  for(int i=0; i < N; ++i){
    cin >> A[i];
    L[i] = 0;
    R[i] = 0;
  }
  for(int i=0; i < N; ++i){
    L[i+1] = gcd(L[i], A[i]);
  }
  reverse(A, A+N);
  for(int i=0; i < N; ++i){
    R[i+1] = gcd(R[i], A[i]);
  }
  for(int i=0; i < N; ++i){
    ans = max(ans, gcd(L[i], R[N-1-i]));
  }
  cout << ans << endl;

  return 0;
}


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

const string S = "KIHBR";

bool check(string str){
  string tmp;
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == 'A')continue;
    tmp += str[i];
  }
  if(!(S == tmp))return false;
  for(int i = 1 ; i < str.size() ; i++){
    if(str[i-1] == 'K'){
      if(str[i] == 'A')return false;
    }
    if(str[i-1] == 'I'){
      if(str[i] == 'A')return false;
    }
    if(str[i-1] == 'A'){
      if(str[i] == 'A')return false;
    }
  }
  return true;
}

int main(){
  string str;
  cin >> str;
  cout << (check(str) ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
  int N,K; cin >> N >> K;
  
  long long x[N]; long long sum,mi; sum=mi=0;
  
  for(int i=0; i<K; i++){cin >> x[i];}
  sum = mi = min(abs(x[0]),abs(x[K-1])) + abs(x[K-1]-x[0]);
  
  if(N==K){cout << mi;}
  else{
  	for(int i=K; i<N; i++){
      cin >> x[i];
      sum = min(abs(x[i-K+1]),abs(x[i])) + abs(x[i]-x[i-K+1]);
      if(sum < mi){mi = sum;}
  	}
    cout << mi;
  }
  
  return 0;
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M, K = (int(i) for i in input().split())
    AB = [[int(i)-1 for i in input().split()] for j in range(M)]
    CD = [[int(i)-1 for i in input().split()] for j in range(K)]

    par = [i for i in range(N)]
    rank = [1 for i in range(N)]

    def find_root(x):
        if par[x] == x:
            return x
        else:
            par[x] = find_root(par[x])
            return par[x]

    def is_same_group(x, y):
        return find_root(x) == find_root(y)

    def unite(x, y):
        x = find_root(x)
        y = find_root(y)
        if x == y:
            return
        if rank[x] < rank[y]:
            x, y = y, x
        rank[x] += rank[y]
        par[y] = x

    def size(x):
        return rank[find_root(x)]

    friends = [[] for _ in range(N)]
    blocks = [[] for _ in range(N)]
    for a, b in AB:
        friends[a].append(b)
        friends[b].append(a)
        unite(a, b)
    for c, d in CD:
        if is_same_group(c, d):
            blocks[c].append(d)
            blocks[d].append(c)
    for i in range(N):
        ans = size(i) - len(friends[i]) - len(blocks[i]) - 1
        print(ans, end=" " if i != N-1 else "\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 129628
//----------------------------------------------------------------
//I

#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

// 入力
int N;
vector<double> p;

// DP テーブル
double dp[3100][3100];

int main() {
    cin >> N;
    p.resize(N);
    for (int i = 0; i < N; ++i) cin >> p[i];

    // 初期条件
    dp[0][0] = 1.0;

    // DP ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    // 答え
    double res = 0.0;
    for (int j = N/2 + 1; j <= N; ++j) res += dp[N][j];
    cout << fixed << setprecision(10) << res << endl;
}





Measured memory_bytes: 50272
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#include<bits/stdc++.h>
using namespace std;
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type,
		less_equal<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
		
typedef tree<int, null_type,
		less<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

bool pal(string x)
{
	string y=x;
	reverse(y.begin(),y.end());
	
	return x==y;
}

void solve()
{
	string x;
	cin>>x;
	
	int n=x.size();
	
	string a=x.substr(0,(n-1)/2);
	string b=x.substr((n+3)/2-1,n);
	
	//cout<<x<<" "<<a<<" "<<b<<"\n";
	
	if(pal(x) && pal(a) && pal(b)) cout<<"Yes";
	else cout<<"No";
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: u64 = itr.next().unwrap().parse().unwrap();
    let b: f64 = itr.next().unwrap().parse().unwrap();

    let c: u64 = (b * 100.0 + 0.5) as u64;
    println!("{}", a * c / 100);
}


Measured memory_bytes: 2152
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;
int n;
int sum[maxn], sum2[maxn];
char s[maxn];

template <typename T>
inline void read(T &k)
{
    int f = 1; k = 0; char c = getchar();
    while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
    while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
    k *= f;
}

int main()
{
    read(n);
    scanf("%s", s + 1);

    for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (s[i] == '#');
    for (int i = n; i; i--) sum2[i] = sum2[i + 1] + (s[i] == '.');
    int ans = inf;
    for (int i = 0; i <= n; i++) ans = min(ans, sum[i] + sum2[i + 1]);//, printf("%d %d\n", sum[i], sum2[i + 1]);
    printf("%d\n", ans);
}

Measured memory_bytes: 3328