akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn main() {
    let a: f32 = read();
    let b: f32 = read();
    let f = |x: f32| { if x.floor() - x == 0.0 { x - 1.0 } else { x.floor() } };
    let (a_min, a_max): (f32, f32) = ((a*12.5).ceil(), f((a+1.0)*12.5));
    let (b_min, b_max): (f32, f32) = ((b*10.0).ceil(), f((b+1.0)*10.0));
    let ans = if a_min <= b_min && b_min <= a_max {
        b_min
    } else if b_min <= a_min && a_min <= b_max {
        a_min
    } else {
        -(1.0)
    };
    println!("{}", ans as i64);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    int rem=n%10;
    if(rem==3)
        cout<<"bon"<<endl;
    else if(rem==0||rem==6||rem==1||rem==8)
        cout<<"pon"<<endl;
    else
        cout<<"hon"<<endl;

    return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

vll dv[N];

void sieve() {
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; j += i) {
            dv[j].push_back(i);
        }
    }
}

int c[N];

int main() {
    sieve();
    int n;
    cin >> n;
    vll v(n);;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        c[v[i]]++;
    }
    sort(all(v));
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        bool ok = true;
        for (int j = 0; j < dv[v[i]].size() - 1; ++j) {
            if (c[dv[v[i]][j]]) {
                ok = false;
                break;
            }
        }
        if (c[v[i]] > 1)
            ok = false;
        ans += ok;
    }
    cout << ans << endl;
}

Measured memory_bytes: 189460
#include <cstdio>
#include <cstdlib>

typedef struct{
    int p;
    int l;
    int r;
}node;

node *nd;

void preorder(int id){
    if(id<0)return;
    printf(" %d",id);
    preorder(nd[id].l);
    preorder(nd[id].r);
}

void inorder(int id){
    if(id<0)return;
    inorder(nd[id].l);
    printf(" %d",id);
    inorder(nd[id].r);
}

void postorder(int id){
    if(id<0)return;
    postorder(nd[id].l);
    postorder(nd[id].r);
    printf(" %d",id);
}

int main(){
    int i, n, id, l, r;
    scanf("%d",&n);
    nd = (node*)malloc(sizeof(node)*n);
    for(i=0;i<n;i++){
        nd[i].p = -1;
        nd[i].l = -1;
        nd[i].r = -1;
    }
    for(i=0;i<n;i++){
        scanf("%d %d %d",&id,&l,&r);
        nd[id].l = l;
        nd[id].r = r;
        if(l>=0)nd[l].p = id;
        if(r>=0)nd[r].p = id;
    }
    int root;
    for(root=0;root<n;root++)if(nd[root].p<0)break;
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
long long h,w;
long long cal(long long H,long long W){
  long long a,b,c,res=1e11;
  for(long long i=1;i<H;i++){
    a=i*W;
    b=W/2*(H-i);
    c=H*W-a-b;
    res=min(res,max(a,c)-min(a,b));
  }
  for(long long i=1;i<H;i++){
    a=i*W;
    b=(H-i)/2*W;
    c=H*W-a-b;
    res=min(res,max(a,c)-min(a,b));
  }
  return res;
}

int main(){
  cin >> h >> w;
  cout << min(cal(h,w),cal(w,h)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>

using namespace std;

long long mod = 1000000007;

long long binpow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = binpow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return binpow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (long long i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (long long i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int main()
{
    long long k, q;
    cin >> k >> q;
    vector<long long> d(k), temp(k);
    long long n, x, m, zerocnt, sm, rez;
    for (int i = 0; i < k; i++)
    {
        cin >> d[i];
    }
    for (int i = 0; i < q; i++)
    {
        cin >> n >> x >> m;
        zerocnt = 0;
        sm = 0;
        rez = 0;
        for (int j = 0; j < k; j++)
        {
            temp[j] = d[j] % m;
            if (temp[j] == 0)
            {
                zerocnt++;
            }
            sm += temp[j];
        }
        sm *= ((n - 1) / k);
        rez += n - 1;
        rez -= zerocnt * ((n - 1) / k);
        for (int j = 0; j < (n - 1) % k; j++)
        {
            sm += temp[j];
            if (temp[j] == 0)
            {
                rez--;
            }
        }
        sm += x % m;
        rez -= sm / m;
        cout << rez << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstring>

#define ll long long

int main()
{
    int N;
    std::cin >> N;

    ll table[N][3];
    memset(table, 0, sizeof(table));
    for (int i=0; i<N; ++i)
    {
        std::cin >> table[i][0] >> table[i][1] >> table[i][2];
    }

    ll dp[N+1][3];
    memset(dp, 0, sizeof(dp));

    for (int i=0; i<N; ++i)
    {
        // a を選択したとき -> 直前に b or c を選択した方のよりよい方
        dp[i+1][0] += std::max(dp[i][1], dp[i][2]) + table[i][0];

        // b を選択したとき
        dp[i+1][1] += std::max(dp[i][0], dp[i][2]) + table[i][1];

        // c を選択したとき
        dp[i+1][2] += std::max(dp[i][0], dp[i][1]) + table[i][2];
    }

    ll max = 0;
    for (int i=0; i<3; ++i)
    {
        if (max < dp[N][i])
            max = dp[N][i];
    }

    std::cout << max << std::endl;
}

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

int main() {
  int n;
  cin >> n;
  struct {
    int n;
    void dfs(const string& s, int m) {
      if (s.length() == n) {
        cout << s << "\n";
        return;
      }
      for (int i = 0; i <= m; i++) {
        dfs(s + char('a' + i), m + (i == m));
      }
    }

  } t = {n};
  t.dfs("", 0);
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define sort stable_sort 
using namespace std;

int _;

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

const int mod=1e9+7;

int n;

inline long long powlog(int x,int t)
{
	long long ans=1;
	while(t--)
	{
		ans *= x;
		ans %= mod;
	} 
	return ans;
}

int main()
{	
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	printf("%lld\n",(powlog(10,n)-powlog(9,n)-powlog(9,n)+powlog(8,n)+2*mod)%mod);
	return 0;
}   	         


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<int> a(100001);
vector<int> dp(100001,-1);
int topDown(int n,int i,int k){
    if(dp[i]!=-1)
        return dp[i];
    if(i==n-1)
        return 0;

    int mmin = 1e18;
    for(int j=1;j<=k;j++){
        if(i<n-j)
            mmin = min (mmin, abs(a[i]-a[i+j]) + topDown(n,i+j,k));
        else break;
    }
    return dp[i] = mmin;
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,m,i,j,k,sum=0;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<topDown(n,0,k)<<'\n';
    



    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,cnt,ma,ans=1,num;
	cin>>n;
	for(int i=1;i<n+1;i++){
		cnt=0;
		num=i;
		for(int j=1;j<7;j++){
			if(num%2==0){
				num/=2;
				cnt++;
			}
			else{break;}
		}
		if(ma<cnt){
			ma=cnt;
			ans=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define all(a) a.begin(),a.end()
#define keepu(a) a.erase(unique(all(a)),a.end())
#define inf 1e7
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("output.txt","r",stdin)
#define write freopen("input.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))
#define pi acos(-1)

typedef long long ll;
const ll M = 1e9+7;
const int sz = 500010;


int main(){
    double n; cin >> n;
    cout << setprecision(30) << (2.0*pi*n) << endl;
    return 0;
}


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

typedef long long ll;
const int mod=1e9+7;

int main(){
    ll a,b,x;
    while(~scanf("%lld%lld%lld",&a,&b,&x)){
        if(a){
            printf("%lld\n",b/x-(a-1)/x);
        }
        else{
            printf("%lld\n",b/x+1);
        }
    }
    return 0;
}


Measured memory_bytes: 3232
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.length();
  int64_t s = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (S[i] != S[i + 1])continue;
    ++s; ++i;
  }
  S += S;
  int64_t d = 0;
  for (int i = 0; i < 2 * N - 1; ++i) {
    if (S[i] != S[i + 1])continue;
    ++d; ++i;
  }
  S += S;
  int64_t t = 0;
  for (int i = 0; i < 3 * N - 1; ++i) {
    if (S[i] != S[i + 1])continue;
    ++t; ++i;
  }
  int64_t ans = s + (t - s) * ((K - 1) / 2) + ((K - 1) % 2 ? d - s : 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  int x, havefh, havefive, left;
  cin >> x;

  havefh = x / 500;
  left = x % 500;

  havefive = left / 5;

  cout << (havefh * 1000) + (havefive * 5) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int main() {
    int a = iin(), b = iin(), c = iin();
    int tmp;
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (a > c) {
        tmp = a;
        a = c;
        c = tmp;
    }
    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}



Measured memory_bytes: 2052
import sys

def main():
    INF = -2**60
    N, M = map(int, sys.stdin.buffer.readline().split())
    XYZ = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

    sgn = [[1,1,1], [1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]
    ans = INF 
    for a, b, c in sgn:
        dp = [INF]*(M+1)
        dp[0] = 0
        for x, y, z in XYZ:
            for j in range(M-1, -1, -1):
                if dp[j] == INF: continue
                s = dp[j]+ a*x + b*y + c*z
                if s > dp[j+1]:
                    dp[j+1] = s
        if dp[M] > ans:
            ans = dp[M]
    print(ans)

main()


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

using namespace  std;

const int mx = 3012;

int dp[mx][mx];
char s[mx],t[mx];


int main(){
    scanf("%s%s", s+1, t+1);
    int lenS = strlen(s+1) , lenT = strlen(t+1);

    for(int i = 1 ; i <= lenS; ++i){
        for(int j = 1 ; j <= lenT; ++j){
            if(s[i] == t[j])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    stack<char> st;
    int ptrS = lenS , ptrT = lenT;
    while(ptrS && ptrT){
//        printf("s t : %d %d\n",ptrS, ptrT);
        if(s[ptrS] == t[ptrT]){
            st.push(s[ptrS]);
            ptrS --; ptrT --;
        } else if(dp[ptrS-1][ptrT] > dp[ptrS][ptrT-1]){
            ptrS --;
        } else {
            ptrT --;
        }
    }
    while(!st.empty()) {
        putchar(st.top());
        st.pop();
    }
    putchar('\n');
    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;
int A[MAX];

void no()
{
	cout<<"No"<<endl;
	exit(0);
}

void yes()
{
	cout<<"Yes"<<endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

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

	int mn = INF;
	int mx = -INF;
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
		mn = min(mn, A[i]);
		mx = max(mx, A[i]);
	}

	if (mx - mn > 1) no();

	if (mx == mn)
	{
		if (mx == n-1) yes();
		if (2 * mx <= n) yes();
		no();
	}

	int c1 = 0, c2 = 0;
	FOR (i, 0, n)
	{
		if (A[i] == mn) c1++;
		if (A[i] == mx) c2++;
	}

	if (c2 <= 1) no();

	int up = c1 + c2 / 2;
	int dn = c1 + 1;
	if (up < mx || dn > mx) no();
	yes();

}


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

int main() {
  int N, D;
  cin >> N >>D;
  int per;
  per = 2*D+1;
  int guard ;
  if(N%per ==0)  cout << N/per << endl;
  else cout << N/per +1 << endl;

  }


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double a, b, x;
  cin >> a >> b >> x;
  double deg = 0;
  if (x >= a * a * b / 2.0) deg = atan(2.0 * (a * a * b - x) / a / a / a);
  else deg = atan(a * b * b / 2.0 / x);
  deg = deg * 180.0 / M_PI;
  printf("%.10f\n", deg);
}


Measured memory_bytes: 256
using static System.Console;

namespace AtCorder
{
	public class Program
	{
		public static void Main()
		{
			var n = int.Parse(ReadLine());
			for (int i = 0; i <= n; i += 4)
			{
				for (int j = 0; j <= n; j += 7)
				{
					if (i + j == n)
					{
						WriteLine("Yes");
						return;
					}
				}
			}
			WriteLine("No");
		}
	}
}


Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
from math import factorial
c = [[0]*2001 for _ in range(2001)]
def init():
	global c
	c[0][0] = 1
	for i in range(2000):
		for j in range(i+1):
			c[i+1][j] += c[i][j]
			c[i+1][j+1] += c[i][j]
def main():
	n, k = map(int, input().strip().split())
	global c
	init()
	for i in range(1, k+1):
		if i-1 > n - k:
			print(0)
			continue
		
		# c = factorial(k-1)//(factorial(k-i)*factorial(i-1))
		# noko = factorial(n-k+1)//(factorial(i) * factorial(n-k-i+1))
		# print(c, noko)
		ans = c[k-1][i-1] * c[n-k+1][i]
		# print(ans)
		ans %= 10**9+7
		print(ans)


if __name__ == '__main__':
	main()


Measured memory_bytes: 478716
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

bool equa(double a,double b){
    return abs(a-b) < EPS;
}

// upper is demi
int solve(double rest,int upper,int n,int k,int a){
    if(equa(rest,0)) return 1;
    if(rest + EPS < 0) return 0;
    if(n == 0) return 0;
    int cnt = 0;
    for(int i=upper;;i++){
        if(1.0/i*n+EPS < rest or k*i > a) break;
        double r = rest - 1.0/i;
        //cerr << "(" << r << "," << i << "," << (n-1) << "," << k*i << ")" << endl;
        cnt += solve(r,i,(n-1),k*i,a);
    }
    return cnt;
}

int main(){
    while(true){
        int p,q,a,n;
        cin >> p >> q >> a >> n;
        if(p == 0) break;

        double retio = 1.0*p/q;
        cout << solve(retio,1,n,1,a) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a, b, c, d] = input[0].split(" ").map((x: string): number => +x);
const hp = [a, c];
while (hp[0] > 0 && hp[1] > 0) {
	hp[1] -= b;
	hp[0] -= d;
}

if (hp[1] <= 0) {
	console.log("Yes");
} else {
	console.log("No");
}


Measured memory_bytes: 29628
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

int main() {
  long long N = 0ul;
  std::cin >> N;
  std::vector<long long> A(N);
  for (auto &i : A) { std::cin >> i; }
  for (auto i = 1; i < N; ++i) { A[i] += A[i - 1]; }
  auto full_len = A[N - 1];
  auto ans = full_len;
  for (const auto &i : A) {
    ans = std::min(ans, std::max(full_len - 2 * i, 2 * i - full_len));
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>

const int MOD = 1000000007;

using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c, n;
  cin >> n;
  a = n / 100;
  b = (n - a * 100) / 10;
  c = n - (a * 100) - (b * 10);

  if (a == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1001001001;
const ll MOD = 1e9 + 7;
const double PI = 3.14159265358979;

int h, w;
char room[2000][2000];
int L[2000][2000], R[2000][2000], D[2000][2000], U[2000][2000];

int main(){
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> room[i][j];
  rep(i, h) rep(j, w){
    if(room[i][j] == '#') L[i][j] = 0;
    else if(j == 0) L[i][j] = 1;
    else L[i][j] = L[i][j-1]+1;
  }
  rep(j, w) rep(i, h){
    if(room[i][j] == '#') U[i][j] = 0;
    else if(i == 0) U[i][j] = 1;
    else U[i][j] = U[i-1][j]+1;
  }
  for(int i = 0; i < h; i++){
    for(int j = w-1; j >= 0; j--){
    if(room[i][j] == '#') R[i][j] = 0;
    else if(j == w-1) R[i][j] = 1;
    else R[i][j] = R[i][j+1]+1;
    }
  }
  for(int j = 0; j < w; j++){
    for(int i = h-1; i >= 0; i--){
    if(room[i][j] == '#') D[i][j] = 0;
    else if(i == h-1) D[i][j] = 1;
    else D[i][j] = D[i+1][j]+1;
    }
  }
  int ans = -INF;
  rep(i, h) rep(j, w) ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3);
  cout << ans <<endl;
}



Measured memory_bytes: 66688
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, k;

    cin >> n >> k;

    ll res = 0;

    for (int i = k + 1; i <= n; i++)
    {
        ll sum = 0;

        ll num = i - k;

        sum += ((n - (i - 1)) / i + 1) * num;

        int ma = (n - (i - 1)) / i;

        int l = k - 1, r = i;

        while (r - l > 1)
        {
            int mid = (l + r) / 2;

            if (mid + i * (ma + 1) > n)
                r = mid;
            else
                l = mid;
        }

        if (r - l)
            sum += l - k + 1;

        if (k == 0)
            sum--;

        res += sum;
    }

    cout << res << endl;

    return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++)
        cin >> X[i];
    int ans = 1 << 30;
    for (int i = 1; i <= 100; i++) {
        int sum = 0;
        for (int j = 0; j < N; j++) {
            sum += (X[j] - i) * (X[j] - i);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int solve(int, int);
int n, q, A[2000];

int main(){
  int i, m[2000];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &m[i]);
  }

  for(i = 0; i < q; i++){
    if(solve(0, m[i]) == 0){
      printf("yes\n");
    }
    else if(solve(0, m[i]) == 1){
      printf("no\n");
    }
  }
  
  return 0;
}

int solve(int i, int m){
  if(m == 0) return 0;

  if(i >= n) return 1;

  if(solve(i+1, m) == 0) return 0;

  return solve(i+1, m - A[i]);
}



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

ll countNum(ll val){
	return (val - 1)*val/2;
}

int main(){
	int n;
	cin>>n;
	string str;
	map<string , ll> _mp;
	for(int i=0; i<n; i++){
		cin>>str;
		sort(str.begin(),str.end());
		_mp[str] += 1;
	}
		
	map<string, ll> :: iterator it = _mp.begin();
	
    ll ans = 0;
	
	for(;it != _mp.end(); it++) {
		if(it->second >= 2) {
			ans += countNum(it->second);
		}
	}
	cout<<ans<<endl;
}


// cat act tac dog god

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

const ll mod=1000000007;

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  if(k<=a)cout<<a-k<<" "<<b<<endl;
  else{
    k-=a;
    if(k<=b){
      cout<<0<<" "<<b-k<<endl;
    }
    else cout<<0<<" "<<0<<endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
vi v;
int n;
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n)
    {
        v = vi(n);
        for(int i = 0; i < n; i++)
            cin >> v[i];
        sort(v.begin(), v.end());
        int ans = min(v[n-1] - v[0], v[0]);
        int sel = v[0];
        for(int i = 1; i < n - 1; i++)
            if(min(v[i], v[n-1] - v[i]) > ans)
            {
                ans = min(v[i], v[n-1] - v[i]);
                sel = v[i];
            }
        cout << v[n-1] << " " << sel << '\n';
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n, T;
    cin >> n >> T;
    ll ans = 0;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];

    rep(i, n - 1) { ans += min(T, t[i + 1] - t[i]); }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long C = long.Parse(str[2]);
		long ans = Math.Min(B,C);
		long ans2 = Math.Max(0,B+C-A);
		Console.WriteLine(ans+" "+ans2);
	}
}

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

import sys


def main():
    input = sys.stdin.readline
    N = int(input())
    X = list(map(int, input().split()))

    p_results = []
    for p in range(0, 100):
        p_sum = 0
        for _, x in enumerate(X):
            p_sum += (x - p) ** 2
        p_results.append(p_sum)
    print(min(p_results))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
N = input()

N_one = int(N[-1])


if N_one == 2 or N_one == 4 or N_one == 5 or N_one == 7 or N_one == 9:
    print("hon")

if N_one == 0 or N_one == 1 or N_one == 6 or N_one == 8:
    print("pon")

if N_one == 3:
    print("bon")


Measured memory_bytes: 9168
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const tokens = input[0].split(' ').map(function(value) { return parseInt(value, 10); });
    const r = tokens[0];
    const g = tokens[1];
    const b = tokens[2];
    const n = tokens[3];

    let ans = 0;

    for (let i = 0; i <= n; i += r) {
        for (let j = 0; j <= n - i; j += g) {
            if ((n - (i + j)) % b === 0) {
                ans++;
            }
        }
    }

    console.log(ans);

    return 0;
}

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

using namespace std;
int n,h;
int a[100001];
int b[100001];
int main() {
  cin >> n >> h;
  int ma = 0;
  int mi;
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if(ma < a[i]) {
      mi = i;
      ma = a[i];
    }
  }
  sort(b,b+n,greater<int>());
  for(int i = 0; i < n; i++) {
    b[i] = max(ma,b[i]);
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(h <= 0) {
      cout << ans << endl;
      return 0;
    }
    
    h-= b[i];
    ans++;
  }
   if(h <= 0) {
      cout << ans << endl;
      return 0;
    }
  if(h % ma == 0) {
    cout << ans + h / ma << endl;
  }
  else {
    cout << ans + h / ma + 1 << endl;
  }

  
 
 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	long long ans = 0;;
    map<long long, long long> s;
	for (int i = 1; i <= n; i++) {
		int a;
		cin>>a;
		ans+=s[i - a];
		s[i + a]++; 
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 26380
#!/usr/bin/env python3
import sys
from collections import Counter
MOD = 998244353  # type: int

def solve(N: int, D: "List[int]"):
    if D[0] != 0:
        print(0)
        return 
    
    for i in range(1,N):
        if D[i]==0:
            print(0)
            return 

    ## 階層が飛んでるものを除く
    D.sort()
    counter = Counter(D).items()
    answer = 1
    prev_node_count = 1
    layer = 0
    for c in counter:
        if layer == c[0]: 
            answer*=prev_node_count**c[1]
            prev_node_count = c[1]
            layer+=1
        else:
            print(0)
            return 
    
    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24040
x = int(input())

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

a = primes(10**5+3)
b = [i for i in a if i>=x]
print(b[0])

Measured memory_bytes: 4068
#include <bits/stdc++.h>
    using namespace std;
    int n,m;
    const long long inf=1000000000000000;
    const int N=200009;
    vector<int>vv[N],v[N];
    pair<int,int>a[N];
    long long laz[4*N*2];
    long long  tree[4*N*2];
    void up(int ind,int st,int end ,int l,int r,long long val)
    {
        if (laz[ind]!=0)
        {
            tree[ind]+=laz[ind];
            if (st!=end){laz[ind*2+1]+=laz[ind];
            laz[ind*2+2]+=laz[ind];}
            laz[ind]=0;
        }
        if (l<=st&&end<=r)
        {
            tree[ind]+=val;
            if (st!=end){laz[ind*2+1]+=val;
            laz[ind*2+2]+=val;}
            return ;
        }
        if (r<st||l>end)return ;
        int m=(st+end )/2;
        up(ind*2+1, st,m , l, r, val);
        up(ind*2+2, m+1,end , l, r, val);
        tree[ind]=max(tree[ind*2+1],tree[ind*2+2]);
    }

    long long query(int ind,int st,int end ,int l,int r)
    {
    //    cout<<st<<" "<<end<<endl;
        if (laz[ind]!=0)
        {
            tree[ind]+=laz[ind];
            if (st!=end){laz[ind*2+1]+=laz[ind];
            laz[ind*2+2]+=laz[ind];}
            laz[ind]=0;
        }
        if (l<=st&&end<=r)
        {return tree[ind];
        }
        if (r<st||l>end)return -inf;
        int m=(st+end )/2;
        return max(query(ind*2+1, st,m , l, r),query(ind*2+2, m+1,end , l, r));
        }
    int main()
    {
        int x,y,z;
        cin>>n>>m;
        for(int i=1;i<m+1;i++)
        {
            cin>>x>>y>>z;
            a[i]=make_pair(x,z);
            v[x].push_back(i);
            vv[y].push_back(i);
        }
        //for(int i=0;i<N*8+12;i++)tree[i]=-inf;
        for(int i=1;i<n+1;i+=1)
        {

            for(auto it:v[i])
            {
                //cout<<a[it].second<<endl;
                up(0,0,n,0,i-1,a[it].second);
            }
            long long x=query(0,0,n,0,i-1);
            up(0,0,n,i,i,x);
            for(auto it:vv[i])
            {
                up(0,0,n,0,a[it].first-1,-a[it].second);
            }
        }
        long long u=0;
        cout<<max(query(0,0,n,0,n),u);
    }


Measured memory_bytes: 36352
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define INF ((lld)1<<55)

int main(){
  lld n,A[10010]; cin >> n;
  for(int i=0;i<n-1;i++){
    cin >> A[i];
  }
  lld dp[5050][2];
  fill_n(*dp,5050*2,INF);
  dp[1][0] = dp[0][1] = 0;
  for(int i=0;i<n-1;i++){
    for(int j=n/2;j>0;j--){
      dp[j][1] = min(dp[j][1],dp[j][0]+A[i]);
      dp[j][0] = min(dp[j-1][0],dp[j-1][1]+A[i]);
    }
  }
  cout << dp[n/2][0] << endl;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

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

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A;
    int all = 0;
    rep(i, N) {
        int a;
        cin >> a;
        all += a;
        A.push_back(a);
    }
    sort(A.begin(), A.end(),greater<>());
    int check = ceil((double) all / (4 * M));
    int count = 0;
    rep(i, N) {
        if (check <= A[i]) {
            count++;
        } else {
            break;
        }
    }
    if (count >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}


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

using namespace std;

int calc(const vector<int> &v, int p)
{
    int an = 0;
    for (auto &x: v) {
        an += (x-p) * (x-p);
    }
    return an;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &x: v) cin >> x;

    int an = INT_MAX;
    for (int p = 1; p <= 100; ++p) {
        an = min(an, calc(v, p));
    }
    cout << an << endl;
    return 0;
}


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

const int MAXN = 1e5+10;
using ll = long long;

int N;
int a[MAXN], b[MAXN], c[MAXN];
ll dp[MAXN][4];
int main() {
    cin >> N;
    for(int i=1; i<=N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, 0, sizeof(dp));
    for(int i=1; i<=N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    ll ans = 0; 
    for(int i=0; i<3; i++) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, M;
    cin >> N >> M;
    vector<pll> v(N);
    ll a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        v[i] = pll(a, b);
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        a = v[i].first, b = v[i].second;
        ans += min(M, b) * a;
        M = max(M - b, 0LL);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1LL * res * a % MOD;
		a = 1LL * a * a % MOD;
		b >>= 1;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	if (n < 2) {
		cout << 0 << "\n";
	} else {
		int total = binpow(10, n);
		int no_zero = binpow(9, n);
		int no_nine = binpow(9, n);
		int no_zero_and_nine = binpow(8, n);
		cout << (0ll + total - no_zero - no_nine + no_zero_and_nine + MOD + MOD) % MOD << "\n";
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

struct ModInt {
 private:
  static int64 M;
  int64 x;
 public:
  static void SetMod(int64 mod) {
    M = mod;
  }
  ModInt(int64 input_x) : x(input_x % M) {}
  ModInt() : x(0) {}
  int64 Value() { return x; }
  inline ModInt operator+(ModInt o) {
    ModInt r(*this); r += o; return r;
  }
  inline ModInt operator-(ModInt o) {
    ModInt r(*this); r -= o; return r;
  }
  inline ModInt operator* (ModInt o) {
    ModInt r(*this); r *= o; return r;
  }
  inline void operator+= (ModInt o) { x = (x + o.x) % M; }
  inline void operator-= (ModInt o) { x = (x + M - o.x) % M; }
  inline void operator*= (ModInt o) { x = (x * o.x) % M; }
};
int64 ModInt::M = 1;  // Do not forget to add this line.

template<typename T>
struct SquareMatrix {
 private:
  vector<vector<T>> matrix;
 public:
  const vector<vector<T>>& Value() { return matrix; }
  SquareMatrix(vector<vector<T>>& in_matrix) : matrix(in_matrix) {}
  SquareMatrix<T> operator*(SquareMatrix<T> o) {
    int n = matrix.size();
    vector<vector<T>> result(n, vector<T>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          result[i][j] += matrix[i][k] * o.matrix[k][j];
        }
      }
    }
    return SquareMatrix(result);
  }
  vector<T> operator*(vector<T> o) {
    int n = matrix.size();
    vector<T> result(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        result[i] += matrix[i][j] * o[j];
      }
    }
    return result;
  }
  // TODO: Rewrite it without a recursion.
  SquareMatrix<T> Power(int64 p) {
    int n = matrix.size();
    if (p == 0) {
      vector<vector<T>> result(n, vector<T>(n));
      for (int i = 0; i < n; i++) result[i][i] = 1;
      return result;
    } else if (p % 2 == 1) {
      return *this * Power(p - 1);
    } else {
      auto m = Power(p / 2);
      return m * m;
    }
  }
};

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

  int64 length, s, d, mod;
  cin >> length >> s >> d >> mod;
  ModInt::SetMod(mod);

  int64 r = 10;
  ModInt answer = ModInt(0);
  bool initialized = false;
  while (true) {
    if (s >= r) {
      r *= 10;
      continue;
    }
    int64 current_length = min(length, (r - 1 - s) / d + 1);
    // cout << "r: " << r << endl;
    // cout << "current_length: " << current_length << endl;

    // Do
    // cout << s << " " << current_length << endl;
    vector<vector<ModInt>> matrix_content {
      {r, d, s},
      {0, 1, 1},
      {0, 0, 1}
    };
    SquareMatrix<ModInt> matrix(matrix_content);
    auto power_result = matrix.Power(current_length);
    auto vector_result = power_result * vector<ModInt>({answer, 0, 1});
    answer = vector_result[0];
    // cout << "answer: " << answer.Value() << endl;

    // To the next level.
    s += d * current_length;
    length -= current_length;
    r *= 10;
    if (length == 0) break;
  }
  cout << answer.Value() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    if (a == b && b == c && a % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    int cnt = 0;
    auto check = [&](ll a, ll b, ll c) {
        return a % 2 == 0 && b % 2 == 0 && c % 2 == 0;
    };
    while (check(a, b, c)) {
        ll ha = a / 2;
        ll hb = b / 2;
        ll hc = c / 2;
        a = hb + hc;
        b = hc + ha;
        c = ha + hb;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
# coding: utf-8

K, N = map(int, input().split())

A = list(map(int, input().split()))
A = sorted(A)
# print(A)

max_dif = 0
for i in range(N-1):
    dif = A[i+1] - A[i]
    # print(dif)
    if dif > max_dif:
        max_dif = dif

if A[0] + (K-A[-1]) > max_dif:
    max_dif = A[0] + (K-A[-1])

print(K - max_dif)


Measured memory_bytes: 26444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long gcd = 0;
            for (int i = 0; i < n; i++) gcd = Maths.gcd(gcd, in.nextLong());
            out.println(gcd);

        }

    }

    static class Maths {
        static long gcd(long a, long b) {
            if (a == 0) {
                return b;
            }
            if (b == 0) {
                return a;
            }

            long r, i;
            while (b != 0) {
                r = a % b;
                a = b;
                b = r;
            }
            return a;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}



Measured memory_bytes: 35168
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    sc.nextLine()
    val ts = sc.nextLine.split(" ").map(_.toInt)
    val m = sc.nextLine.toInt
    val drinks = List.fill(m)(sc.nextLine.split(" ").map(_.toInt))
    drinks.map{d => ts.sum + (d(1) - ts(d(0) - 1))}.foreach(println)
  }
}


Measured memory_bytes: 25668
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    int64_t a, b;
    cin >> a >> b;
    cout << a + (int)(b / 2) << endl;
    return 0;
}



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

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "local":
        with open("stdin.txt") as stdin:
            main(stdin.readline)
    else:
        main(sys.stdin.readline)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		int co=0;
		vvi in(n+1,vi(4));
		rep(i,n+1)rep(j,4)cin>>in[i][j];
		rep(i,n){
			if(in[i][3]<=in[n][2]&&in[i][1]<=in[n][0]&&in[i][2]<=in[n][1]&&(in[i][1]+in[i][3])*4+in[i][2]*9<=in[n][3]){
				co++;
				cout<<in[i][0]<<endl;
			}
		}
		if(!co)cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 3228
n = int(input())
a_dist = {'AC' : 0, 'WA' : 0, 'TLE' : 0, 'RE' : 0}
for i in range(n):
  a = input()
  a_dist[a] = a_dist[a] + 1
for a, a_n in a_dist.items():
  print(f'{a} x {a_n}')

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

#define D 2000

int main(){
	int count=0;
	int N;
	int command,x;
	int MAX_D=D;
	int *L=(int*)malloc(sizeof(int)*D);
	int *L2=(int*)malloc(sizeof(int)*D);

	scanf("%d",&N);

	for(int i=0;i<N;i++){
		scanf("%d",&command);
		switch(command){
		case 0:
			scanf("%d",&x);
			L[count++]=x;
			break;
		case 1:
			scanf("%d",&x);
			printf("%d\n",L[x]);
			break;
		case 2:
			count--;
			break;
		}
		if(count==MAX_D){
			for(int j=0;j<MAX_D;j++){
				L2[j]=L[j];
			}
			free(L);
			L=(int*)malloc(sizeof(int)*(MAX_D+D));
			for(int j=0;j<MAX_D;j++){
				L[j]=L2[j];
			}
			MAX_D+=D;
			free(L2);
			L2=(int*)malloc(sizeof(int)*MAX_D);
		}
	}

	return 0;
}


Measured memory_bytes: 2952
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define all(v) v.begin(),v.end()
const ll mod=1000000007;
ll cnt[200005];
 
 
using namespace std;
 
bool sortcol(pll i, pll j){
	return i.first < j.first;
}
 
ll fib(ll n) { 
  double phi = (1 + sqrt(5)) / 2; 
  return round(pow(phi, n) / sqrt(5)); 
} 
 
int main() {
		 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
	ll N, K, x, i;
	
	cin >> N;
	ll ans = 0;
	
	vector<pll>A;
	
	for(i=0; i<N; i++){
		cin >> x;
		A.pb(make_pair(x,i+1));
	}
	sort(all(A), sortcol);
	
	for(i=0; i<N; i++){
		cout << A[i].second << " ";
	}
	
		
	
}


Measured memory_bytes: 2544