akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define rep(i,a) for(int i = 0 ; i < a ; i++) 

char maze[21][21];
int dx[4] = { 0, 0,-1, 1};
int dy[4] = {-1, 1, 0, 0};
int H,W;
bool inmaze(int x,int y){
  return (0<=x && x<H) && (0<=y && y<W);
}

int dfs(int x,int y){
  if(!inmaze(x,y))return 0;
  maze[x][y] = '#';
  int res = 1;
  rep(i,4){
    if(maze[x+dx[i]][y+dy[i]] == '.'){
      res += dfs(x+dx[i],y+dy[i]);
    }
  }
  return res;
}
int main(void){
  while(cin>>W>>H,H+W){
    int sx,sy;
    rep(i,H){
      string s;
      cin>>s;
      rep(j,W){
	maze[i][j] = s[j];
	if(s[j] == '@'){
	  sx = i;sy = j;
	}
      }
    }
    maze[sx][sy] = '.';
    cout<<dfs(sx,sy)<<endl;
  }
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i;
	ll a[225816],ans=INFLL;
	a[0] = 0ll;
	cin >> n;
	for(i=1; i<=n; ++i){
		cin >> a[i];
		a[i] += a[i-1];
	}
	for(i=1; i<n; ++i){
		ans = min(ans,abs(a[i]*2-a[n]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))


N, X = inpl()

def main(N, X):
    B = [0]
    P = [1]
    T = [1]
    
    for i in range(50):
        b, p, t = B[-1], P[-1], T[-1]
        B.append(2*b + 2)
        P.append(2*p + 1)
        T.append(2*t + 3)
    
    ans = 0
    for n in range(N, 0, -1):
        if X <= T[n-1]:
            X -= 1
        elif X <= T[n-1] + 2:
            ans += P[n-1] + (X == T[n-1]+2)
            break
        elif X < 2*T[n-1] + 2:
            ans += P[n-1] + 1
            X -= (T[n-1] + 2)
        else:
            ans += 2*P[n-1] + 1
            break
    return ans

print(main(N, X))

Measured memory_bytes: 3064
// ------ Includes ------ //

#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <iostream>

using namespace std;


// ------ Directions ------ //

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


// ------ BFS ------ //

int BFS(vector<vector<int> > p)
{
	// ------ Initialize ------ //

	vector<vector<int> > lastboard = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 0 } };

	map<vector<vector<int> >, int> D;

	queue<pair<vector<vector<int> >, int> > que;

	D[p] = 1; que.push(make_pair(p, 1));


	// ------ Search ------ //

	if (p == lastboard)
	{
		return 0;
	}

	while (!que.empty())
	{
		pair<vector<vector<int> >, int> p1 = que.front(); que.pop();


		// ------ 0 Searching ------ //

		int tx = -1, ty = -1;

		for (int i = 0; i < p1.first.size(); i++)
		{
			for (int j = 0; j < p1.first[i].size(); j++)
			{
				if (p1.first[i][j] == 0)
				{
					tx = j; ty = i;
				}
			}
		}


		// ------ Moving ------ //

		for (int dir = 0; dir < 4; dir++)
		{
			if (0 <= tx + dx[dir] && tx + dx[dir] < p1.first[0].size() && 0 <= ty + dy[dir] && ty + dy[dir] < p1.first.size())
			{
				vector<vector<int> > p2 = p1.first;

				swap(p2[ty][tx], p2[ty + dy[dir]][tx + dx[dir]]);

				if (D[p2] == 0)
				{
					if (p2 == lastboard)
					{
						return p1.second;
					}

					D[p2] = p1.second + 1;

					que.push(make_pair(p2, p1.second + 1));
				}
			}
		}
	}

	return -1;
}

int main()
{
	vector<vector<int> > board(3, vector<int>(3, -1));;

	for (int i = 0; i < board.size(); i++)
	{
		for (int j = 0; j < board[i].size(); j++)
		{
			cin >> board[i][j];
		}
	}

	cout << BFS(board) << endl;

	return 0;
}

Measured memory_bytes: 49372
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static double height, max ,min = Integer.MAX_VALUE;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
		System.out.println(max - min);
	}
	static boolean read(){
		if(!sc.hasNext())
			return false;
		height = sc.nextDouble();
		return true;
	}
	static void solve(){
		max = Math.max(max, height);
		min =  Math.min(min, height);
	}
}

Measured memory_bytes: 12000
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def fact(n):
    b = 2
    li = []
    li.insert(0,1)
    while b*b<=n:
        while n%b == 0:
            n = n//b
            li.append(b)
        b+=1
    if n>1:
        li.append(n)

    return li
a,b = map(int,input().split())
c = gcd(a,b)
ans = set(fact(c))
print(len(ans))






Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll X;
  cin >> X;
  ll ans = 0;
  ans += X/500 * 1000;
  X %= 500;
  ans += X/5 * 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

// 1_000_000_000_000_001 = 10^15 + 1

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

int main()
{
    ll N;
    cin >> N;
    string ans;
    
    while (N > 0)
    {
        --N;
        int i = N % 26;
        ans.push_back('a' + i);
        N /= 26;
    }
    reverse(begin(ans), end(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3

import itertools


def find_eq(abcd):
    a, b, c, d = abcd
    ops = ("+", "-")
    for op1, op2, op3 in itertools.product(ops, repeat=3):
        eq = a + op1 + b + op2 + c + op3 + d
        if eval(eq) == 7:
            return eq + "=7"


def main():
    print(find_eq(input()))


if __name__ == '__main__':
    main()


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

int main(){
    int N, M, a, b;
    cin >> N >> M;
    int i1[200001], iN[200001];
    for(int i=0;i<200001;i++){
      i1[i]=0;
      iN[i]=0;
    }
    for(int i=0;i<M;i++){
        cin >> a >> b;
        if(a == 1)
            i1[b] = 1;
        if(b == N)
            iN[a] = 1;
    }
    for(int i=0;i<=N;i++){
        if(i1[i] == 1 && iN[i] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
from math import sqrt

def main():
    N = int(input())
    ans = 1e12 + 1
    for i in range(1, int(sqrt(N)) + 1):
        if N % i == 0:
            j = N // i
            ans = min(ans, i + j - 2)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;

signed main(){
	int x;cin>>x;
	if(x<30)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  int N;
  int ali = 0, bob = 0;

  cin >> N;
  int a[N];

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

  int sum = accumulate(a, a + N, 0);
  sort(a, a + N);
  for(int i = N-1; i >= 0; i-=2){
    ali += a[i];
  }
  cout << ali - (sum - ali) << endl;

  return 0;
}

Measured memory_bytes: 256
from math import sqrt, factorial

if __name__ == "__main__":
    n = int(input())
    xy = list()
    for i in range(n):
        tmp = list(map(float, input().split()))
        xy.append(tmp)

    # まず2街間の距離を全部求める
    distance = list()
    for i in range(n):
        for j in range(n):
            if i is j:
                continue
            distance.append(
                sqrt((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2))

    ans = 0
    for d in distance:
        ans += d * factorial(n-1)

    print(ans / float(factorial(n)))


Measured memory_bytes: 3064
//Problem E
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=4005,p=998244353;
ll n,k,ans[N],inv[N],fac[N],inv_fac[N];
ll c(ll a,ll b){if(a<b)return 0;return fac[a]*(inv_fac[a-b]*inv_fac[b]%p)%p;}
ll solve(ll a,ll n,ll k){
    ll ans=0;
    --n;
    for(ll i=0;i<=min(a,k>>1);i++){
        ll cal=c(a,i)*c(n+k-i-i,n)%p;
        if(i&1)ans=(ans-cal+p)%p;
        else ans=(ans+cal)%p;
    }
    return ans;
}
int main(){
    scanf("%lld%lld",&n,&k);
    fac[0]=inv_fac[0]=inv[1]=fac[1]=inv_fac[1]=1;
    for(ll i=2;i<N;i++){
        inv[i]=(p-p/i)*inv[p%i]%p;
        fac[i]=fac[i-1]*i%p;
        inv_fac[i]=inv_fac[i-1]*inv[i]%p;
    }
    for(ll i=1;i<=n;i++){
        ll a=i>>1;
        if(i&1)ans[i]=(solve(a,n-1,k)+solve(a,n-1,k-1))%p;
        else ans[i]=solve(a,n,k);
    }
    for(ll i=1;i<=n;i++)printf("%lld\n",ans[i]);
    for(ll i=n-1;i;i--)printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 384
n = int(input())

red = []
blue = []

for i in range(n):
    red.append(tuple(map(int, input().split())))
for i in range(n):
    blue.append(tuple(map(int, input().split())))

red.sort(key=lambda x:x[1])
red.reverse()

blue.sort(key=lambda x:x[0])

res = 0

for b in range(n):
    for r in range(len(red)):
        if blue[b][0] > red[r][0] and blue[b][1] > red[r][1]:
            res += 1
            del red[r]
            break

print(res)


Measured memory_bytes: 3064
H , W = map(int,input().split())
stage = list(list(input()) for _ in range(H))

dx = [0,1,0,-1]
dy = [1,0,-1,0]
for i in range(H):
    for j in range(W):
        if stage[i][j] == ".":
            continue
        Flag = True
        for k in range(4):
            if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H and stage[i + dy[k]][j + dx[k]] == "#":
                Flag = False
                break
        if Flag:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
#include<string.h>
#define FOR(N) for(int i = 0;i < N;i++)
#define PRN(N) printf("%d\n",N)
#define PRS(S) printf("%s\n",S)

int main(void){
  char s[10],c[10];
  scanf("%s",&s);
  int a = 1,b = 0,f = 1;
  FOR(5){
    if(!i){
      c[0] = s[0];
    }else{
      if(c[0] == s[i]){
        a++;
      }else if(f || c[1] == s[i]){
        b++;
        c[1] = s[i];
        f = 0;
      }
    }
  }
  if(a == b && a == 2){
    PRS("Yes");
  }else{
    PRS("No");
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m, c;
  cin >> n >> m >> c;

  vll b(m);
  rep(i, m) {
    cin >> b[i];
  }

  ll ans = 0;

  rep(k, n) {
    vll a(m);
    ll sum = c;
    rep(i, m) {
      cin >> a[i];
      sum += a[i] * b[i];
    }
    if (sum > 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq
N = int(input())
a = list(map(int, input().split()))
m = len(a) // 2

cumsumA = []
prefix = [x for x in a[:N]]
heapq.heapify(prefix)
cumsumA.append(sum(prefix))
cursum = sum(prefix)
for k in range(N, 2*N):
  heapq.heappush(prefix, a[k])
  ele = heapq.heappop(prefix)
  cursum = cursum + a[k] - ele
  cumsumA.append(cursum)
  # cumsumA.append(sum(prefix))

cumsumB = []
suffix = [-x for x in a[2*N:]]
heapq.heapify(suffix)
cumsumB.append(-sum(suffix))
cursum = -sum(suffix)
for k in range(2*N-1, N-1, -1):
  heapq.heappush(suffix, -a[k])
  ele = heapq.heappop(suffix)
  cursum = cursum + a[k] + ele
  cumsumB.append(cursum)

res = -float('inf')
for i in range(0, len(cumsumA)):
  res = max(res, cumsumA[i] - cumsumB[len(cumsumA)-i-1])

print(res)

Measured memory_bytes: 120208
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

long long gcd(long long x,long long y)
{
    if (x%y == 0){
        return y;
    }
    else {
        return gcd(y,x%y);
    }
}

long long lcm(long long x,long long y)
{
    return x/gcd(x,y) * y;
}

long long rutwo(long long x)
{
    long long r = 0;
    while (x%2 == 0){
        x = x/2;
        r++;
    }
    return r;
}

int main()
{
    long long n,m;
    cin >> n >> m;
    vector<long long>  a;
    long long k;
    for (int i = 0;i < n;i++){
        cin >> k;
        a.push_back(k);
    }
    
    
    sort(a.begin(),a.end(),greater<long long>());
    
    bool check = true;
    
    long long tworui[100005];
    
    for (int i = 0;i < n;i++){
        tworui[i] = rutwo(a[i]);
    }
    
    for (int i = 0;i < n-1;i++){
        if (tworui[i] != tworui[i+1]){
            check = false;
            cout << 0 << endl;
            break;
        }
    }
    
    if (check){
        long long g = a[0]/2;
        for (int i = 0;i < n;i++){
            g = lcm(g,a[i]/2);
        }
    
        cout << (m/g + 1)/2 << endl;
    }
}


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

using namespace std;

int main() {
    string s, t;

    cin >> s >> t;

    if(s.size() + 1 == t.size() && t.substr(0, s.size()) == s) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 3620
n = int(input())

l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def moji(mes, layer, lim):
    if(layer==n):
        print(mes)
        return
    for i in range(lim+1):
        moji(mes+l[i], layer+1, max(lim,i+1))
    return

moji("", 0, 0)

Measured memory_bytes: 4340
x, y = map(int, input().split())

A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
one,zero,m1,n_remain_picks = [int(s) for s in input().split()]
result = 0
if n_remain_picks <= one:
    result = n_remain_picks
    n_remain_picks = 0
else:
    result = one
    n_remain_picks -= one
    if n_remain_picks > zero:
        n_remain_picks -= zero
        result -= min(n_remain_picks, m1)
        n_remain_picks -= min(n_remain_picks, m1)

print(result)


Measured memory_bytes: 9176
s = input()
ans10 = 0
ans01 = 0
for i in range(len(s)):
  if i%2==0:
    if s[i]=="0":
      ans10+=1
    if s[i]=="1":
      ans01+=1
  if i%2==1:
    if s[i]=="1":
      ans10+=1
    if s[i]=="0":
      ans01+=1
print(min(ans10,ans01))

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var c1_1, c1_2, c1_3, c2_1, c2_2, c2_3, c3_1, c3_2, c3_3 int
	fmt.Scan(&c1_1, &c1_2, &c1_3, &c2_1, &c2_2, &c2_3, &c3_1, &c3_2, &c3_3)

	d1 := c2_1 - c1_1
	d2 := c2_2 - c1_2
	d3 := c2_3 - c1_3
	if d1 != d2 || d2 != d3 || d3 != d1 {
		fmt.Println("No")
		return
	}
	d1 = c3_1 - c2_1
	d2 = c3_2 - c2_2
	d3 = c3_3 - c2_3
	if d1 != d2 || d2 != d3 || d3 != d1 {
		fmt.Println("No")
		return
	}
	d1 = c1_1 - c3_1
	d2 = c1_2 - c3_2
	d3 = c1_3 - c3_3
	if d1 != d2 || d2 != d3 || d3 != d1 {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
}


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

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

typedef complex<double> P;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

int ccw(P a,P b,P c){
	P d = b-a;
	c-=a;
	double cr = cross(d,c);
	if(cr < -EPS) return 1;
	if(cr > EPS) return -1;
	if(dot(d,c) < -EPS) return 2;
	if(norm(d) < norm(c)-EPS) return -2;
	return 0;
}


int is_intersected_ls(P a1, P a2, P b1, P b2) {
	return ccw(a1,a2,b1) * ccw(a1,a2,b2) <= 0 &&
		   ccw(b1,b2,a1) * ccw(b1,b2,a2) <= 0;
}

double distance_ls_p(P a, P b, P c) {
	// cout << a << " " << b << " " << c << endl;;
	if(dot(b - a, c - a) < EPS) return abs(c - a);
	if(dot(a - b, c - b) < EPS) return abs(c - b);
	return abs(cross(b - a, c - a)) / abs(b - a);
}

int main() {
	int n, a, b;
	cout << fixed << setprecision(20);
	const double PI = acos(-1);
	while(cin >> n >> a >> b, n) {
		a--, b--;
		vector<vector<P>> v(n, vector<P>(5));
		rep(i, n) {
			double x, y, k, r;
			cin >> x >> y >> k >> r;
			rep(j, 5) {
				double rad = 360.0 / 5 * j + 90 + k;
				rad *= PI / 180;
				v[i][j] = P(r * cos(rad) + x, r * sin(rad) + y);
			}
		}
		vector<vector<double> > dp(n, vector<double>(n, 1e100));
		rep(i, n) dp[i][i] = 0;
		rep(i, n) {
			rep(j, n) {
				if(i==j) continue;
				double t = 1e100;
				rep(k, 5) {
					rep(l, 5) {
						if(is_intersected_ls(v[i][k], v[i][(k + 2) % 5], v[j][l], v[j][(l + 2) % 5])) t = 0;
						if(is_intersected_ls(v[i][k], v[i][(k + 3) % 5], v[j][l], v[j][(l + 2) % 5])) t = 0;
						if(is_intersected_ls(v[i][k], v[i][(k + 2) % 5], v[j][l], v[j][(l + 3) % 5])) t = 0;
						if(is_intersected_ls(v[i][k], v[i][(k + 3) % 5], v[j][l], v[j][(l + 3) % 5])) t = 0;
						t = min(t, distance_ls_p(v[i][k], v[i][(k + 2) % 5], v[j][l]));
						t = min(t, distance_ls_p(v[i][k], v[i][(k + 3) % 5], v[j][l]));
						t = min(t, distance_ls_p(v[j][l], v[j][(l + 2) % 5], v[i][k]));
						t = min(t, distance_ls_p(v[j][l], v[j][(l + 3) % 5], v[i][k]));
					}
				}
				dp[i][j] = t;
			}
		}
		rep(k, n) {
			rep(i, n) {
				rep(j, n) {
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}
		cout << dp[a][b] << endl;
	}
}

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

int gcd(int, int, int);

int main() {
	int K;
	int i, j, k;
	int sum = 0;
	int st;
	cin >> K;
	for (i = 1; i <= K; i++) {
		for (j = 1; j <= K; j++) {
			for (k = 1; k <= K; k++) {
				st=gcd(i , j, k);
				sum += st;
			}
		}
	}
	cout << sum;
	return 0;
}

int gcd(int a, int b, int c) {
	int min;
	int ans = 1;
	int i;
	if (a < b) {
		min = a;
	}
	else {
		min = b;
	}
	if (c < min) {
		min = c;
	}
	for (i = min; i >= 2; i--) {
		if (a%i == 0 && b%i == 0 && c%i == 0) {
			ans *= i;
			a /= i;
			b /= i;
			c /= i;
		}
		if (a == 1 || b == 1 || c == 1) break;
	}
	return ans;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second

struct Tree {
	typedef int T;
	static constexpr T unit = INT_MIN;
	T f(T a, T b) { return max(a, b); } // (any associative fn)
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void update(int pos, T val) {
		for (s[pos += n] = val; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}
};

int main()
{
	cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    Tree t(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        t.update(i,a[i]);
    }

    ll ans = 0;
    for(int i = 1; i < n; i++)
    {
        int v = t.query(0,i);
        //db(v)
        if(a[i] >= v) continue;
        ans += (v-a[i]);
        t.update(i,v);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5568
from bisect import *
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

count = 0

for i in range(N):
  a = bisect_left(A, B[i])
  c = bisect(C, B[i])
  c = N - c
  count += (a*c)

print(count)

Measured memory_bytes: 22720
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[] h = new int[N];
       for(int i = 0; i < N; i++){
           h[i] = sc.nextInt();
       }
       Arrays.sort(h);
       int[] dp = new int[N];
       dp[0] = 0;
       for(int i = 0; i < N-1; i++){
           dp[i+1] = dp[i] + (h[i+1] - h[i]); 
       }
       int min = dp[K-1] - dp[0];
       for(int i = 0; i < N-K+1; i++){
           if(min > (dp[K-1+i] - dp[i]))
            min = dp[K-1+i] - dp[i];
       }
       System.out.println(min);
    }
}


Measured memory_bytes: 50100
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
struct Edge {
    int to,next,val;
    bool operator < (const Edge& rhs)const{
        return val>rhs.val;
    }
} edge[N*2];
int tot, head[N];
void addEdge(int from, int to, int val) {
//    edge[cnt] = Edge{v, head[u], w};
//    head[u] = cnt++;
    edge[tot].next=head[from];
    edge[tot].to=to;
    edge[tot].val=val;
//    edge[tot]=Edge{to,head[from],val};
    head[from]=tot++;
}
bool vis[N];
int dis[N];
void SPFA(int s,int e) {
    priority_queue<Edge> q;
    memset(dis,INF,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[s] = 0;
    q.push(Edge{s, 0, 0});
    while (!q.empty()) {
        Edge u = q.top();
        q.pop();
        if(vis[u.to]) continue;
        vis[u.to] = 1;

        for (int i = head[u.to]; ~i; i = edge[i].next) {
            int to = edge[i].to;
            if (dis[to] > dis[u.to] + edge[i].val) {
                dis[to] = dis[u.to] + edge[i].val;
                q.push(Edge{to, 0, dis[to]});
            }
        }
    }
    printf("%d\n", dis[e] == INF?-1:dis[e]/2);
}

map<int,int> mp[N];
int allPoint;
int getPoint(int x,int y) {
    if (!mp[x][y])
        mp[x][y]=++allPoint;
    return mp[x][y];
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    allPoint=n;
    for (int i=1; i<=m; i++) {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);

        int newX=getPoint(x,w);
        int newY=getPoint(y,w);
        addEdge(x,newX,1);
        addEdge(newX,x,1);
        addEdge(newX,newY,0);
        addEdge(newY,newX,0);
        addEdge(y,newY,1);
        addEdge(newY,y,1);
    }
    SPFA(1,n);

    return 0;
}


Measured memory_bytes: 93556
/*
    Author: aksayushx
*/

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 998244353
using namespace std;
typedef long long ll;
typedef long double ld;

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
ll power(ll x, ll y)  
{  
    ll res = 1; 
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x)%mod;  
        y = y>>1; 
        x = (x*x)%mod;  
    }  
    return res;  
} 
void aksayushx()
{
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(ll i=0;i<n;i++)
    cin>>h[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=pow(10,9);
        ll x=1;
        while(x<=k && i-x>=0)
        {
            dp[i]=min(dp[i],abs(h[i]-h[i-x])+dp[i-x]);
            x++;
        }
    }
    cout<<dp[n-1]<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 4732
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[81][81];
ll b[81][81];
int main()
{
    ll h,w;
    cin>>h>>w;

    forn(i,h)
    forn(j,w)
    cin>>a[i][j];

    forn(i,h)
    forn(j,w)
    cin>>b[i][j];

    bool dp[h][w][80*(h+w)+1];
    forn(i,h)
    forn(j,w)
    forn(k,(ll)80*(h+w)+1)
    dp[i][j][k]=0;

    dp[0][0][abs(a[0][0]-b[0][0])]=1;

    forn(i,h)
    forn(j,w)
    forn(k,(ll)80*(h+w)+1){
        if((i-1)>=0) dp[i][j][k]|=(dp[i-1][j][k+abs(a[i][j]-b[i][j])]|dp[i-1][j][abs(k-abs(a[i][j]-b[i][j]))]);
        if((j-1)>=0) dp[i][j][k]|=(dp[i][j-1][k+abs(a[i][j]-b[i][j])]|dp[i][j-1][abs(k-abs(a[i][j]-b[i][j]))]);
        //cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
    }


    ll m=80*(h+w);
    forn(k,(ll)80*(h+w)+1)
    if(dp[h-1][w-1][k]==1)
    m=min(m,k);
    cout<<m;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  int x=1;int y=N;
  rep(i,M){
    int a,b;
    cin >> a >> b;
    x=max(a,x);
    y=min(y,b);
  }
  cout << max(0,y-x+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;


int main() {
	double n,x,t;
	cin >> n >> x >> t;
	x = ceil(n/x);
	cout << int(x * t) << endl;
}

Measured memory_bytes: 3728
import java.util.*;

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

    int n = sc.nextInt();
    String s = sc.next();
    char[] array = new char[n];
    array = s.toCharArray();
    boolean flag = true;

    if(n%2==0){
      int fs = n/2;
      for(int i=0; i<fs; i++){
        if(array[i]!=array[i+fs]){
          flag = false;
          break;
        }
      }
      if(flag){
        System.out.println("Yes");
      }else{
        System.out.println("No");    
      }
    }else{
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 25300
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int N = 3;
int cost[N][N];
int main()
{
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> cost[i][j];
        }
    }
    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            for (int k = 0; k <= 100; k++)
            {
                vector<int> data;
                data.push_back(i);
                data.push_back(j);
                data.push_back(k);
                vector<int> data1(N, -1);
                bool ok = true;
                for (int a = 0; a < N; a++)
                {
                    for (int b = 0; b < N; b++)
                    {
                        int res = cost[a][b] - data[a];
                        if (res < 0 or res > 100)
                        {
                            ok = false;
                            break;
                        }
                        if (data1[b] != -1 and data1[b] != res)
                        {
                            ok = false;
                        }
                        data1[b] = res;
                    }
                }
                if (ok)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

int main(){
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int M = max(X, Y);
    long long res = 10000000000;
    long long p , q;
    long long r = 0;
    while(r <= 2*M){
        p = X - r/2;
        q = Y - r/2;
        if(p<0) p=0;
        if(q<0) q=0;
        res = min(res, A*p + B*q + C*r);
//        cout << p << "-" << q << "-" << r << endl;
//        cout << A*p + B*q + C*r << endl;
        r = r + 2;
    }
    cout << res << endl;
}

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

int N,E,Q;
int G[500][500];
int visited[500];
int dfs(int pos,int ti,int f){
  if(pos==ti)return f;
  if(visited[pos])return 0;
  visited[pos]=1;
  for(int i=0;i<N;i++){
    int e=G[pos][i];
    if(e==0)continue;
    int k=dfs(i,ti,min(f,e));
    if(k==0)continue;
    G[pos][i]-=k;
    G[i][pos]+=k;
    return k;
  }
  return 0;
}
int ans;
void maxflow(int si,int ti){
  ans=0;
  while(1){
    memset(visited,0,sizeof(visited));
    int f=dfs(si,ti,1);
    if(f==0)break;
    ans+=f;
  }
}

int main(){
  cin>>N>>E>>Q;
  for(int i=0;i<E;i++){
    int F,T;
    cin>>F>>T;
    F--,T--;
    G[F][T]++;
    G[T][F]++;
  }

  maxflow(0,N-1);
  for(int i=0;i<Q;i++){
    int M,A,B;
    cin>>M>>A>>B;
    A--,B--;
    
    if(M==1){
      G[A][B]++;
      memset(visited,0,sizeof(visited));
      ans+=dfs(0,N-1,1);
      G[B][A]++;
      memset(visited,0,sizeof(visited));
      ans+=dfs(0,N-1,1);
    }else{

      if(G[A][B]>0){
        G[A][B]--;
      }else{
        G[B][A]--;
        memset(visited,0,sizeof(visited));
        if( dfs(A,B,1) == 0 ){
          memset(visited,0,sizeof(visited));
          dfs(N-1,B,1);
          memset(visited,0,sizeof(visited));
          dfs(A,0,1);
          ans--;
          memset(visited,0,sizeof(visited));
          ans+=dfs(0,N-1,1);
        }
      }

      if(G[B][A]>0){
        G[B][A]--;
      }else{
        G[A][B]--;
        memset(visited,0,sizeof(visited));
        if( dfs(B,A,1) == 0 ){
          memset(visited,0,sizeof(visited));
          dfs(N-1,A,1);
          memset(visited,0,sizeof(visited));
          dfs(B,0,1);
          ans--;
          memset(visited,0,sizeof(visited));
          ans+=dfs(0,N-1,1);
        }
      }
      
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4068
#include<stdio.h>
int main(void)
{
	int n,array[100],i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d",&array[i]);
	}
	for(i=n-1;i>=0;i--){
	printf("%d",array[i]);
		if(i!=0){
		printf(" ");
	}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2668
n = int(input())
a = list(map(int,input().split()))
flg = 0
ans = 0
for i in range(1,n):
  if a[i] == a[i-1]:
    continue
  elif a[i] > a[i-1]:
    if flg == -1:
      ans += 1
      flg = 0
    else:
      flg = 1
  elif a[i] < a[i-1]:
    if flg == 1:
      ans += 1
      flg = 0
    else:
      flg = -1
print(ans+1)

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

using namespace std;
#define ll long long

const int N = 1e5 + 5;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int ct[2][2];

    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            cin>>ct[i][j];
    
    ll maxVal = -1e19;
    for(int j=0;j<2;j++)
    {
        ll val = ct[0][j];
        val = val * ct[1][j];

        maxVal = max(maxVal, val);

        val = ct[0][j];
        val = val * ct[1][1-j];
        maxVal = max(maxVal, val);
    }

    cout<<maxVal<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main()
{
    int n, k;
    cin >> n;
    string S;
    cin >> S;
    cin >> k;
    for (int i = 0; i < n; i++) {
        if(S[i] != S[k - 1])
            S[i] = '*';
    }
    cout << S << endl;
    return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int A[100010]={};
	int B[100010]={};
	lint asum=0;
	lint bsum=0;
	int cnt=0;
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> A[i];
		B[i]=-A[i];
		asum+=A[i];
		bsum+=B[i];

		if(A[i]<0)
			cnt++;
	}


	if(cnt%2==0)
	{
		lint ans=0;
		for(int i=0;i<N;i++)
			ans+=abs(A[i]);
		cout << ans << endl;
		return 0;
	}

	lint ans=-1e18;
	lint sum=0;
	for(int i=0;i<N;i++)
		sum+=abs(A[i]);
	for(int i=0;i<N;i++)
	{
		ans=max(ans,sum-2*abs(A[i]));
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  string s;
  cin >> k >> s;
  if ((int) s.size() <= k) {
    cout << s << "\n";
  } else {
    s.resize(k);
    cout << s << "...\n";
  }
  return 0;
}


Measured memory_bytes: 3664
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val N = S.length

    data class LR(var left: Long, var right: Long)
    var X = Array(N+1){LR(0L,0L)}
    var i = 0
    while (i < N) {
        var j = i
        var ln = 1L
        while (j < N && S[j] == '<') {
            X[j + 1].left = ln++
            j++
        }
        if (i<j) {
            i = j
        } else {
            i++
        }
    }

    i = N-1
    while (0 <= i) {
        var j = i
        var ln = 1L
        while (0 <= j && S[j] == '>') {
            X[j].right = ln++
            j--
        }
        if (j<i) {
            i = j
        } else {
            i--
        }
    }

    val ans = X.fold(0L){sum, lr->
        sum + max(lr.left, lr.right)
    }
    println(ans)
}


//val rd = debug.Reader("agc", "040", "a", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 67704
#include <cstdio>
#include <cstring>

char S[4];

int main(){
  scanf("%s", S);
  if(!strcmp("SUN", S)) puts("7");
  else if(!strcmp("MON", S)) puts("6");
  else if(!strcmp("TUE", S)) puts("5");
  else if(!strcmp("WED", S)) puts("4");
  else if(!strcmp("THU", S)) puts("3");
  else if(!strcmp("FRI", S)) puts("2");
  else if(!strcmp("SAT", S)) puts("1");

  return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int minn(int a, int b) {
    if(a == -1) return b;
    if(b == -1) return a;
    return min(a, b);
}

int gdist(vector<int>& a, int x, bool right) {
    auto it = lower_bound(a.begin(), a.end(), x);
    if(right) {
        if(it == a.end()) return -1;
        return *it - x;
    } else {
        if(it == a.begin()) return -1;
        it--;
        return x - *it;
    }
}

int32_t main() {

    int a, b, q; cin >> a >> b >> q;
    vector<int> s(a), t(b);
    for(int i = 0; i < a; ++i) cin >> s[i];
    for(int i = 0; i < b; ++i) cin >> t[i];

    while(q--) {
        int x; cin >> x;
        int ans = -1;
        
        int rs = gdist(s, x, true);
        if(rs != -1) {
            int r = gdist(t, x+rs, true);
            int l = gdist(t, x+rs, false);
            rs += minn(r, l);
            ans = minn(ans, rs);
        }

        int ls = gdist(s, x, false);
        if(ls != -1) {
            int r = gdist(t, x-ls, true);
            int l = gdist(t, x-ls, false);
            ls += minn(r, l);
            ans = minn(ans, ls);
        }

        int rt = gdist(t, x, true);
        if(rt != -1) {
            int r = gdist(s, x+rt, true);
            int l = gdist(s, x+rt, false);
            rt += minn(r, l);
            ans = minn(ans, rt);
        }

        int lt = gdist(t, x, false);
        if(lt != -1) {
            int l = gdist(s, x-lt, true);
            int r = gdist(s, x-lt, false);
            lt += minn(r, l);
            ans = minn(ans, lt);
        }
        
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 5e5 + 17;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

char s[maxN];
int sum = 0;

struct Giant {
	int a[maxN], n;

	void input() {
		scanf("%s", s);
		n = strlen(s);
		reverse(s, s+n); -- n;
		rep (i, 0, n) a[i] = s[i] - '0';
	}

	void digit_sum() {
		sum = 0;
		rep (i, 0, n) sum += a[i];
	}

	void operator *= (int d) {
		int c = 0;
		for (int i = 0; i <= n || c; ++ i) {
			c = (a[i] = a[i] * d + c) / 10;
			a[i] %= 10;
			n = max(n, i);
		}
	}

	void operator += (int c) {
		for (int i = 0; c; ++ i) {
			sum -= a[i];
			c = (a[i] += c) / 10;
			a[i] %= 10;
			sum += a[i];
			n = max(n, i);
		}
	}
}a;

int main() {

	a.input();
	a *= 9;
	a.digit_sum();

	rep (k, 1, a.n + 5) {
		a += 9;
		if (9 * k >= sum) { printf("%d\n", k); break; }
	}

	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

// greatest common divisor
long long gcd(long long a, long long b) {
	if (a < b) swap(a, b);
	if (a % b == 0) {
		return b;
	} else {
		return gcd(b, a % b);
	}
}

long long f(long long x, long long c, long long d) {
	return x - x/c - x/d + x/(c*d/gcd(c, d));
}

int main(void) {
	long long A, B, C, D;
	scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
	long long ans = f(B, C, D) - f(A - 1, C, D);
	// printf("%lld %lld %lld", cnum, dnum, cdnum);
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[3];
	int i=0;
	int b[2];
	int c=0;
	int d=0;
	for(i=0;i<3;i++){
		cin>>a[i];
	}
	cin>>b[0];
	cin>>b[1];
	if(a[0]<a[1]){
		c=a[0];
	}else{
		c=a[1];
	}
	if(a[2]<c){
		c=a[2];
	}
	if(b[0]<b[1]){
		d=c+b[0]-50;
	}else{
		d=c+b[1]-50;
	}
	cout<<d<<endl;
}

Measured memory_bytes: 3104
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<stack<int>> s(n);
    int a, t, x;
    while (q--) {
        cin >> a >> t;
        if (a == 0) {
            cin >> x;
            s[t].push(x);
        }
        else if (a == 1) {
            if (s[t].empty())
                continue;
            else
                cout << s[t].top() << endl;
        }
        else {
            if (s[t].empty())
                continue;
            else
                s[t].pop();
        }
    }
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

//最小公倍数
int lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}

int main(){
    int N;
    cin >> N;
    vector<ll>A(N), B(N);
    REP(i, N){
        cin >> A[i];
        B[i] = A[i] - (i + 1);

    }
 
 sort(all(B));
 
 ll ce = B[(N - 1) / 2];
 ll ans = 0;
    REP(i, N){
        ans += abs(B[i] - ce);
    }
print(ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main () {
  int  a, b, c;
  while (1){
      a = getchar();
      if (a == '\n') {
          cout << endl;
          break;
      }
      if (isupper(a)) cout << char (tolower(a));
      else if (islower(a)) cout << char (toupper(a));     
      else cout << char (a);
}
}


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

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

using ll = long long;
using namespace std;

bool
is_palindrome (
    const string & s)
{
    auto b = s.begin();
    auto e = s.end() - 1;
    for (; b <= e; b++, e--) {
      if ( *b != *e ) return false;
    }
    return true;
}

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

    auto l = s.length();
    auto b = s.begin();
    auto sub_s = string(b, b + (l-1)/2);

    auto answer = is_palindrome(s) && is_palindrome(sub_s);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
	int i,s1,s2,t1,t2;
	cin>>s1>>s2>>t1>>t2;
	for(i=1;i<=t2-s2;i++)  cout<<"U";
	for(i=1;i<=t1-s1;i++) cout<<"R";
	for(i=1;i<=t2-s2;i++)  cout<<"D";
	for(i=1;i<=t1-s1;i++) cout<<"L";
	cout<<"L";
	for(i=1;i<=t2-s2+1;i++)  cout<<"U";
	for(i=1;i<=t1-s1+1;i++) cout<<"R";
	cout<<"D";
	cout<<"R";
	for(i=1;i<=t2-s2+1;i++)  cout<<"D";
	for(i=1;i<=t1-s1+1;i++) cout<<"L";
	cout<<"U";
	return 0;
}


Measured memory_bytes: 256