akhauriyash/Code-Regression huggingface dataset:
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
# mod = 998244353
# mod = 10 ** 9 + 9
mod = 10 ** 9 + 7
PI = Math::PI
dx = [ 1,  0, -1,  0,  1,  1, -1, -1]
dy = [ 0,  1,  0, -1,  1, -1,  1, -1]
eight = [0, 1, 1, 0, -1, -1, 1, -1, 0]
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end
def gi;             gets.to_s.to_i                             end
def gf;             gets.to_s.to_f                             end
def gs;             gets.to_s.chomp                            end
def gmi(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_i} : n.times.map{ gets.to_s.to_i } end
def gmf(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_f} : n.times.map{ gets.to_s.to_f } end
def gms(n=nil); n.nil? ? gets.to_s.split : n.times.map{ gets.to_s.chomp } end
def ga2i(h);        h.times.map{ gets.to_s.split.map{|t|t.to_i} }      end
def gm(h);        Array.new(h){ gets.to_s.split.map{|t|t.to_i} }      end
def yn(f); puts f ? "Yes" : "No" end
#def YN(f); puts f ? "YES" : "NO" end
def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil); f.nil? ? (puts "No"; exit) : (puts f ? "Yes" : "No") end
def yay(f=nil); f.nil? ? (puts "Yay!"; exit) : (puts f ? "Yay!" : ":(") end

#n = gets.to_s.to_i
a, b, c, k = gets.to_s.split.map{|e|e.to_i}
#m = Array.new(n){ gets.to_s.split.map{|e|e.to_i} }
# s = gets.to_s.chomp
# t = gets.to_s.chomp

if k <= a
  puts k
elsif k <= a + b
  puts a
elsif k <= a + b + c
  puts a - ( k - a -b )
end

Measured memory_bytes: 14376
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll a[n+1], b[m+1];
	for(ll i=1; i<=n; i++)
		cin>>a[i];
	for(ll i=1; i<=m; i++)
		cin>>b[i];
	a[0] = 0; b[0] = 0;
	for(int i=1; i<=n; i++)
		a[i] += a[i-1];
	for(int i=1; i<=m; i++)
		b[i] += b[i-1];
	ll ma = 0;
	ll p2 = 0;
	for(int i=n; i>=0; i--)
	{
		if(a[i] + b[p2] > k) continue;
		while(p2 <=m && b[p2] <= k-a[i]) p2++;
		p2--;
		ma = max(ma, i+p2);
	}
	cout<<ma<<nl; 
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	//cin>>t;
	t = 1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  ll x;
  cin >> N >> x;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> B(N-1);
  rep(i, N-1)
    B[i] = max(0LL, A[i+1] + A[i] - x);
  ll cnt = 0;
  rep(i, N) {
    int b = max(0LL, min(B[i], A[i+1]));
    if(i == 0) {
      A[i] -= B[i] - b;
      cnt += B[i] - b;
    }
    A[i+1] -= b;
    B[i+1] -= b;
    cnt += b;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
using namespace std;
char s[20];
long long ans, n;
bool pls[20];
long long work() 
{
  long long t=0,sum=0;
  for(int i=0;i<n-1;i++) 
  {
    t=t*10+s[i];
    if(pls[i])  sum+=t,t=0;
  }
  t=t*10+s[n-1];
  return t+sum;
}
void dfs(int k) 
{
  if(k==n-1) 
  {
    ans += work();
    return;
  }
  pls[k] = false;dfs(k + 1);
  pls[k] = true;dfs(k + 1);
}
int main() 
{
  scanf("%s",&s);
  n=strlen(s);
  for(int i=0;i<n;i++)  s[i]-='0';
  dfs(0);
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 128
from collections import deque

h, w = map(int,input().split())
alist = [input().strip() for i in range(h)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]

INF = 99999
dp = [[INF]*w for i in range(h)]
q = deque()
for y, row in enumerate(alist):
  for x, c in enumerate(row):
    if c=='#':
      dp[y][x] = 0
      q.append((x,y))

while q:
  x, y = q.popleft()
  d = dp[y][x]
  for dx, dy in dxy:
    nx, ny = x+dx, y+dy
    if not 0 <= nx < w:
      continue
    if not 0 <= ny < h:
      continue
    if dp[ny][nx] <= d+1:
      continue
    dp[ny][nx] = d+1
    q.append((nx,ny))

print(max(max(row) for row in dp))


Measured memory_bytes: 89180
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
#include<set>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }


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

	ll N;
	cin >> N;

	vl P(N);
	vl ind(N);
	rep(i, N) {
		cin >> P[i];
		ind[P[i] - 1] = i;
	}

	multiset<ll> si{ -1, -1, N, N };
	ll ret = 0;
	rrep(i,N){
		ll k = ind[i];
		si.insert(k);
		auto it = si.find(k);
		ll l1 = *prev(it);
		ll l2 = *prev(prev(it));
		ll r1 = *next(it);
		ll r2 = *next(next(it));
		ret += (i+1) * ((r2 - r1) * (k - l1) + (l1 - l2) * (r1 - k));
	}

	cout << ret << endl;


	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<char>> A(N, vector<char>(N));
	vector<vector<char>> B(M, vector<char>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A.at(i).at(j);
		}
	}
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < M; j++) {
			cin >> B.at(i).at(j);
		}
	}

	bool exist = false;
	for (int y1 = 0; y1 <= N - M; y1++) {
		for (int x1 = 0; x1 <= N - M; x1++) {
			bool match = false;

			if (A.at(y1).at(x1) == B.at(0).at(0)) {
				bool match = true;

				for (int y2 = 0; y2 < M; y2++) {
					for (int x2 = 0; x2 < M; x2++) {
						if (B.at(y2).at(x2) != A.at(y1 + y2).at(x1 + x2)) {
							match = false;
							break;
						}
					}
				}

				if (match) {
					exist = true;
					break;
				}
			}
		}
	}

	if (exist) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	void minmaxsum(){
		Scanner s = new Scanner(System.in);
		int i = s.nextInt();
		long max,min,sum;
		max = -1000001;
		min = 1000001;
		sum = 0;
		for(int j = 0;j < i;j++){
			int tmp = s.nextInt();
			if(max < tmp)max = tmp;
			if(min > tmp)min = tmp;
			sum+=tmp;
		}
		System.out.println(min + " " + max + " " + sum);
	}
	public static void main(String args[]){
		Main m = new Main();
		m.minmaxsum();
	}
}

Measured memory_bytes: 41588
import networkx as nx

import io
import os


input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, D = [int(x) for x in input().split()]
XY = [[int(x) for x in input().split()] for i in range(N)]

graph = nx.DiGraph()
for i in range(2 * N):
    graph.add_node(i)

# f_i = 0 means choose x for flag i, f_i = 1 means choose y
# Node i is (f_i==0), node (i+N) is (f_i==1)
for i, (x1, y1) in enumerate(XY):
    for j in range(N):
        if i != j:
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                # f_i==0 => f_j==1
                graph.add_edge(i, j + N)
            if abs(x1 - y2) < D:
                # f_i==0 => f_j==0
                graph.add_edge(i, j)
            if abs(y1 - x2) < D:
                # f_i==1 => f_j==1
                graph.add_edge(i + N, j + N)
            if abs(y1 - y2) < D:
                # f_i==1 => f_j==0
                graph.add_edge(i + N, j)


SCC = nx.algorithms.components.strongly_connected_components(graph)
assignment = {}
for comp in SCC:
    for x in comp:
        if (x < N and x + N in comp) or (x >= N and x - N in comp):
            print("No")
            exit()
        if x not in assignment:
            assignment[x] = True
            assignment[(x + N) % (2 * N)] = False

print("Yes")
for i in range(N):
    print(XY[i][0] if assignment[i] else XY[i][1])



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; string s; cin>>n>>s;
  
  vll l(n+1);
  rep(i,n){
    l[i+1]=l[i];
    if(s[i]=='W') l[i+1]++;
  }
  
  vll r(n+1);
  rrep(i,n){
    r[i]=r[i+1];
    if(s[i]=='E') r[i]++;
  }
  
  ll ans=LINF;
  rep(i,n){
    chmin(ans, l[i]+r[i+1]);
  }
  cout<<ans<<endl;
  
}

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

int main(){

	string str,str1,str2;
	int m,h;
	
	while(1){
		cin >> str;
		if(str=="-")break;
		cin >> m;
		for(int i=0; i<m; i++){
			cin >> h;
			str1 = str.substr(0,h);
			str2 = str.substr(h,str.size()-h);
			str = str2 + str1;
		}
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 3160
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		System.out.println((n-2)*180);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
unit = ["", "Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]

toStr 0 _ = []
toStr _ [] = []

toStr n (u:us) = 
  let m = n `mod` 10000
      n'= n `div` 10000
  in
    if m == 0
    then (toStr n' us)
    else (toStr n' us) ++ show(m) ++ u

ans' :: Integer -> Integer -> String
ans' a b =
  let n = a ^ b
  in
    toStr n unit

ans :: [[Integer]] -> [String]
ans ([0,0]:_) = []
ans ([a,b]:s) =
  (ans' a b):(ans s)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Integer]]
      o = ans i
  mapM_ putStrLn o

Measured memory_bytes: 4356
n = int(input())
l = list(map(int, input().split()))
s = sorted(l)
cost = 0
for i in range(n):
    a = l.index(s[i])
    j = 0
    while a > i:
        j += 1
        b = l.index(s[a])
        cost += l[b]
        l[a], l[b] = l[b], l[a]
        a = b
    cost += min(s[i] * j, s[i] * 2 + s[0] * (j + 2))
print(cost)

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

public class Solution
{
    public static bool IsK(string[] grid, int bx, int by, int k)
    {
        var count = 0;
        for (int y = 0; y < grid.Length; y++)
        {
            if (((1 << y) & by) != 0)
            {
                continue;
            }
            for (int x = 0; x < grid[0].Length; x++)
            {
                if (((1 << x) & bx) != 0)
                {
                    continue;
                }
                if (grid[y][x] == '#')
                {
                    count++;
                }
            }
        }

        return count == k;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var H = vals[0];
        var W = vals[1];
        var K = vals[2];
        var grid = new string[H];
        for (int y = 0; y < H; y++)
        {
            grid[y] = Console.ReadLine();
        }

        var count = 0;
        for (int y = 0; y < (1 << H); y++)
        {
            for (int x = 0; x < (1 << W); x++)
            {
                if (IsK(grid, x, y, K))
                {
                    count++;
                }
            }
        }

        Console.WriteLine(count);
    }
}

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

int main() {
  int n; cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  int ans = 1e9;

  rep(i,101){
    int score = 0;
    rep(j,n) score += (vec[j]-i)*(vec[j]-i);
    if(score < ans) ans = score;
  }

  cout << ans << endl;
}


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

int main(){
  
  int n; cin>>n;
  for(int i=1; i<=n; i++){
    if(i%3==0) cout <<' '<<i;
    else{
      auto j = i;
      while(j){
        if(j%10==3) {
          cout <<' '<<i;
          break;
        }
        j /= 10;
      }
    }
  }
  cout << endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=1e9;
  cin >> n;
  for(int i=1;i<=n/2;i++){
  	long long a=i,b=n-i,sum=0;
  	while(a){
  	  sum+=a%10;
  	  a/=10;
  	}
  	while(b){
  	  sum+=b%10;
  	  b/=10;
  	}
  	ans=min(ans,sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
while True:
    n,x= map(int,raw_input().split())

    if n == x == 0:
        break

    count = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i + j + k == x:
                     count = count + 1
                     break
    print count

Measured memory_bytes: 6444
p,q,a,N,c;D(n,d,x,k){if(p*d==q*n)c++;else if(k<N&&p*d>q*n)for(;x*d<=a;x++)D(n*x+d,x*d,x,k+1);}
main(){for(;scanf("%d%d%d%d",&p,&q,&a,&N),N;printf("%d\n",c))D(c=0,1,1,0);exit(0);}

Measured memory_bytes: 600
a,b=map(int,input().split())
s=input()
n=["0","1","2","3","4","5","6","7","8","9"]
for i in range(len(s)):
    if i==a:
        if s[i] in n:
            print("No")
            exit()
    else:
        if not s[i] in n:
            print("No")
            exit()
print("Yes")

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

int triple_max(int x, int y, int z);

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a-b < 0 ? 0 : a-b) << endl;


    return 0;
}

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,a,b,c;
  int count = 0;
  
  scanf("%d %d %d",&a,&b,&c);
  
  for(i=a;i<=b;i++){
  	if(c%i == 0){
    	count++;
    }
    else;
  }
  
  printf("%d\n",count);
  
  return 0;
}


Measured memory_bytes: 2060
#include<stdio.h>
#define M  1000000
int main(){
  int n,m,i,j,d[30];
  char p[M]={1,1};
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  while(scanf("%d %d",&n,&m),n||m){
    int dp[M]={1};
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    for(i=0;i<=m+1;i++){
      if(dp[i]==0)continue;
      for(j=0;j<n;j++){
	if(i+d[j]>m)continue;
	dp[i+d[j]]=1;
      }
    }
    for(i=m;1+p[i]-dp[i];i--)if(i<2)break;
    if(i<2)printf("NA\n");
    else   printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 5500
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		int a[]=new int [4];
		int b[]=new int [4];
		int sum1=0;
		int sum2=0;

		for(int i=0; i<4;i++)
			sum1 += sc.nextInt();
		for(int i=0; i<4;i++)
			sum2 += sc.nextInt();
		if(sum1>=sum2)
			System.out.println(sum1);
		else
			System.out.println(sum2);
	}

}

Measured memory_bytes: 12000
import sys
import math
from pprint import pprint

A, B, N = map(int, sys.stdin.readline().strip().split())

def func(x):
    return math.floor(A*x/B) - A*math.floor(x/B)
    # return A*x//B - A*(x//B)

print(func(min(B-1, N)))

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

int main() {
    cout << fixed << setprecision(8);
    int a, b, x;  cin >> a >> b >> x;
    double PI = acos(-1);
    if (2 * x > a * a * b) cout << atan(2.0 * (a * a * b - x) / (a * a * a)) * 180 / PI << endl;
    else cout << atan(a * b * b / (2.0 * x)) * 180 / PI << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public string S;
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            S = Console.ReadLine();
            N = S.Length;

            int count = Math.Max(CheckCenter('0'), CheckCenter('1'));
            Console.WriteLine((N + count) / 2);
        }

        public int CheckCenter(char c)
        {
            int count = 0;
            int l, r;
            if (N % 2 == 0)
            {
                l = N / 2 - 1;
                r = N / 2;
            }
            else
            {
               l = N / 2;
               r = N / 2;
            }

            while (true)
            {
                if (S[l] == c && S[r] == c)
                {
                    count += (l == r ? 1 : 2);
                    l--;
                    r++;
                }
                else
                {
                    return count;
                }
                if (l < 0) return count;
            }

        }

    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i,N){
		cin >> S[i];
		sort(S[i].begin(), S[i].end());
	}
	
	sort(S.begin(),S.end());
	map<string,int> mp;
	ll ans = 0;
	rep(i,N){
		if(mp[S[i]] != 0){
			ans += mp[S[i]];
		}
		mp[S[i]]++;
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 13568
def main():
    s = list(input())[::-1]
    ary_mod = [0] * 2019
    ary_mod[0] = 1
    now = 0
    digit = 1
    for i, ss in enumerate(s):
        now += int(ss) * digit % 2019
        digit *= 10
        digit %= 2019
        remind = now % 2019
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 79088
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i);
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
ll gcd(const ll &a,const ll &b){
    return b == 0 ? a : gcd(b,a%b);
}
int main(){
    ll n,x;read(n);read(x);
    printf("%lld\n",3LL*(n - gcd(n,x)));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MAXN 105
int N, W, w, v, ans;
map<int, int> H;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	H[0] = 0;
	cin >> N >> W;
	for (int i = 0 ; i < N ; ++i) {
		cin >> w >> v;
		vector<pair<int, int>> tmp;
		for (const auto &p : H) {
			tmp.push_back(p);
		}
		for (const auto &p : tmp) {
			int nv = p.first + v;
			int nw = p.second + w;
			if (nw <= W) {
				auto it = H.find(nv);
				if (it == H.end()) {
					H[nv] = nw;
				} else {
					it->second = min(it->second, nw);
				}
				ans = max(ans, nv);
			}
		}
	}
	cout << ans << '\n';
}

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

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int Y = sc.nextInt();
        sc.close();

        loop: for(int i = 0; i  <= 2000; i++){
            for(int j = 0; j <= 2000-i; j++){
                int k = N - i - j;
                if(k < 0)
                    continue loop;
                if(10000*i + 5000*j + 1000*k == Y){
                    System.out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int H, W;
    cin >> H >> W;
    string S[H];
    rep(i, H) cin >> S[i];
    bool used[H][W];
    rep(i, H) rep(j, W) used[i][j] = false;
    ll b, w, ans = 0;
    rep(p, H) rep(q, W){
        b = w = 0;
        if(used[p][q]) continue;
        queue<pii> que;
        que.push(pii(p, q));
        while(!que.empty()){
            int x = que.front().first, y = que.front().second;
            que.pop();
            if(used[x][y]) continue;
            used[x][y] = true;
            if(S[x][y] == '#') b++;
            else w++;
            rep2(i, -1, 1) rep2(j, -1, 1){
                if(i*j != 0 || i+j == 0) continue;
                if(x+i < 0 || x+i >= H || y+j < 0 || y+j >= W) continue;
                if(used[x+i][y+j]) continue;
                if(S[x+i][y+j] == S[x][y]) continue;
                que.push(pii(x+i, y+j));
            }
        }
        ans += b*w;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
int n, arr[105];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	REP(i, 0, n) cin>> arr[i];
	int ans = 0;
	REP(i, 0, n){
		if (i % 2 == 0 && arr[i]%2 == 1) ans++;
	}
	cout << ans << endl;
}

//cout.flush()

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>



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


map<string, int> mp;
#define ll long long



int main() {
    string s;
    cin >> s;
    int c[2];
    rep(i, s.size()) {
        if (s[i] == 'A') {
            c[0] = i;
            break;
        }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            c[1] = i;
            break;
        }
    }
    cout << c[1] - c[0] + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        200005
#define mod         1000000007 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,sum=0,x,y,z;
    cin>>n;
    ll a[n];
    map<ll,ll> mp1;
    for(i=0;i<n;i++){
        cin>>a[i];
        mp1[a[i]]++;
    }
    for(auto x:mp1){
        sum+=(x.se*1ll*(x.se-1))/2;
    }
    // cout<<sum<<" ";
    for(i=0;i<n;i++){
        x=mp1[a[i]];
        y=mp1[a[i]]-1;
        z=sum-(x*1ll*(x-1))/2+(y*1ll*(y-1))/2;
        cout<<z<<endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

vector<vector<int>> adj;
vector<int> oe;

void dfs(int n=0, int p=-1) {
  for (auto x: adj[n]) {
    if (x==p) continue;
    else {
      oe[x] = !oe[n];
      dfs(x,n);
    }
  }
}

int main() {
  int N; cin >> N;
  adj.resize(N);
  rep(i,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  oe.resize(N,-1); oe[0] = 0;
  dfs();
  // debug(all(oe));
  vector<int> o, e;
  rep(i,N) { if (oe[i]) o.push_back(i); else e.push_back(i); }
  int result[N];
  bool used[N+1] = {};
  if (o.size()*3<=N) {
    rep(i,o.size()) {
      result[o[i]] = (i+1)*3;
      used[(i+1)*3] = true;
    }
    int now = 1;
    for (auto x: e) {
      while(used[now]) now++;
      result[x] = now;
      used[now] = true;
    }
  }
  else if (e.size()*3<=N) {
    rep(i,e.size()) {
      result[e[i]] = (i+1)*3;
      used[(i+1)*3] = true;
    }
    int now = 1;
    for (auto x: o) {
      while(used[now]) now++;
      result[x] = now;
      used[now] = true;
    }
  }
  else {
    rep(i,(N+2)/3) result[o[i]] = i*3+1;
    rep(i,(N+1)/3) result[e[i]] = i*3+2;
    int now = 3;
    repr(i,(N+2)/3,o.size()) { result[o[i]] = now; now += 3; }
    repr(i,(N+1)/3,e.size()) { result[e[i]] = now; now += 3; }
  }
  debug(result,result+N);
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 18164
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a;
	cin>>a;
	if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'){
		cout<<"vowel"<<endl;
	}else{
		cout<<"consonant"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    
    int evenZeroCnt = 0;
    int oddZeroCnt = 0;
    for(int i=0; i<s.length(); i++) {
      if(i%2!=0 && s.charAt(i)=='1')
        evenZeroCnt++;
      else if(i%2==0 && s.charAt(i)=='0')
        evenZeroCnt++;
      
      if(i%2==0 && s.charAt(i)=='1')
        oddZeroCnt++;
      else if(i%2!=0 && s.charAt(i)=='0')
        oddZeroCnt++;
    }
    
    System.out.println(Math.min(evenZeroCnt,oddZeroCnt));
  }
}

Measured memory_bytes: 34744
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int l,r,d;cin>>l>>r>>d;
    int ans = 0;
    rep(i,l,r+1){
        if (i%d==0) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
double sum = 0;
int n = 0;
int main()
{
    int x[9][2];
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%d%d",&x[i][0],&x[i][1]);
    }
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
        {
            sum+=sqrt((x[i][0]-x[j][0])*(x[i][0]-x[j][0])+(x[i][1]-x[j][1])*(x[i][1]-x[j][1]));
        }
    }
    double ans = sum/n;
    printf("%lf",ans);
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()

if K==1:
    print(0)
else:
    print(N-K)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

class A {
	int N, K;
public:
	void solve()
	{
		if (!(N % K)) cout << 0 << endl;
		else cout << 1 << endl;

	}
	A() { cin >> N >> K; }
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

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

int gcd(int x, int y){
    if (x == y){
        return x;
    }
    else {
        return gcd(min(x,y), max(x,y) - min(x,y));
    }
}

int64_t count(int64_t x, int64_t c, int64_t d){
    int64_t lcm = c * d / gcd(c,d);
    return x - x/c - x/d + x/lcm;

}

int main(){
    int64_t A,B,C,D;
    cin >> A >> B >> C >> D;

    cout << count(B,C,D) - count(A-1,C,D) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    vector<ll> pla(n+1);
    for (int i=0; i<n; i++) {
        pla.at(a.at(i)) = i+1;
    }
    set<int> s;
    s.insert(0);
    s.insert(n+1);
    ll ans = 0;
    for (ll i=n; i>0; i--) {
        if (i < n) {
            ll a = 0, b = 0, c = 0, d = 0;
            auto iter = s.upper_bound(pla.at(i));
            if (iter == s.begin() && iter == s.end()) {
                a = b = 0, c = d = n+1;
            }
            else {
                if (*iter == n+1) {
                    c = d = n+1;
                }
                else {
                    c = *iter;
                    iter++;
                    d = *iter;
                }
                iter = s.upper_bound(pla.at(i));
                iter--;
                if (*iter == 0) {
                    a = b = 0;
                }
                else {
                    b = *iter;
                    iter--;
                    a = *iter;
                }
            }
            ans += ((b-a) * (c-pla.at(i)) + (pla.at(i)-b) * (d-c)) * i;
        }
        s.insert(pla.at(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6144
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half -1], s_x[half]
    for i in x:
        b = bisect.bisect_left(s_x, i)
        print(m_l if b < half else m_s)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 25180
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int r, g, b;
    cin >> r >> g >> b;

    int A = 10 * g + b;
    if (A % 4 == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=1e7;
bool aa[mx+10],v[mx+10],mp[1010][1010];
int n,pr[2000010],a[1010],b[1010],bb[1010],c[1010],ans,mlby;
void ycl(){
	int i,j;
	for(i=2;i<=mx;i++){
		if(!v[i])pr[++pr[0]]=i;
		for(j=1;j<=pr[0]&&i*pr[j]<=mx;j++){
			v[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}
	v[1]=v[2]=1;
}
int pd(int x){
	int i;
	if(bb[x])return 0;
	bb[x]=1;
	for(i=1;i<=b[0];i++)if(mp[x][i]&&(!c[i]||pd(c[i]))){
		c[i]=x;return 1;
	}
	return 0;
}
int main(){
	int i,x,j;
	ycl();
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		aa[x]=1;
	}
	for(i=1;i<=mx+1;i++)if(aa[i]!=aa[i-1]){
		if(i%2)a[++a[0]]=i;
		 else b[++b[0]]=i;
	}
	for(i=1;i<=a[0];i++)
	 for(j=1;j<=b[0];j++)if(!v[abs(a[i]-b[j])])mp[i][j]=1;
	for(i=1;i<=a[0];i++){
		for(j=1;j<=a[0];j++)bb[j]=0;
		if(pd(i))ans++;
	}
	mlby=ans+2*((a[0]-ans)/2+(b[0]-ans)/2);
	if((a[0]-ans)%2)mlby+=3;
	printf("%d",mlby);
}

Measured memory_bytes: 24960
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(''))

  const s = input[0].sort()
  const t = input[1].sort().reverse()
  if (s.join('') === t.join('')) {
    console.log('No')
    return
  }
  const concat = [s.slice(0), t.slice(0)].sort()
  const ans = concat[0].join('') == s.join('') ? 'Yes' : 'No'
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    string s; cin >> s;

    if(s.size() == 1) {cout << s << endl; return 0;}
    else {
        bool check = true;
        rep1(i,s.size()) {
            if(s[i] != '9') {check = false; break;}
        }
        if(check) {cout << (s[0] - '0') + 9*(s.size()-1) << endl; return 0;}
        else {cout << (s[0]-'0') + 9*(s.size()-1)-1 << endl; return 0;}
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <stdio.h>
#include <algorithm>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)


int main(){
    int n;
    cin >> n;
    ll l[2] = {2, 1};
    rep(i, n - 1){
        l[i % 2] = l[0] + l[1];
    }
    cout << l[n % 2] << '\n';
}

Measured memory_bytes: 256
K, N = map(int, input().split())
points = list(map(int, input().split()))
max_index = -1
max_value = -1

for index in range(1, N):
  d = points[index] - points[index-1] 
  if d > max_value:
    max_index = index
    max_value = d

start = K - points[max_index]
end   = points[max_index-1]

l = start + end
plane_l = points[-1] - points[0]
if l <= plane_l:
  print(l)
else:
  print(plane_l)

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

/*
N -> N-1 ~ N+1 で /2
    -> N-2 ~ N+2 で /3
	-> N-4 ~ N+4 で /5
	-> 0まで-1
*/

void challenge(long long n, long long new_cost, queue<long long> *pq, map<long long, long long> *pcost)
{
	if ((*pcost)[n] != 0 && (*pcost)[n] <= new_cost)
	{
		return;
	}
	(*pcost)[n] = new_cost;
	if (n > 1)
	{
		(*pq).push(n);
		// cout << "cost[" << n << "]=" << new_cost << ", "
		// 	 << "push " << n << "\n";
	}
	return;
}

int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int T;
	scanf("%d", &T);

	for (int i = 0; i < T; i++)
	{
		long long N, A, B, C, D;
		scanf("%lld %lld %lld %lld %lld", &N, &A, &B, &C, &D);
		map<long long, long long> cost;
		cost[N] = 1; //1多い.
		queue<long long> q;
		q.push(N);
		long long N_tmp;
		while (!q.empty())
		{
			N_tmp = q.front();
			// cout << "N_tmp=" << N_tmp << "\n";
			q.pop();
			if (N_tmp == 1)
			{
				cost[0] = cost[N_tmp] + D;
				continue;
			}
			challenge((N_tmp - N_tmp % 2) / 2, cost[N_tmp] + (N_tmp % 2) * D + A, &q, &cost);
			if (N_tmp % 2 != 0)
			{
				challenge((N_tmp - N_tmp % 2) / 2 + 1, cost[N_tmp] + (2 - (N_tmp % 2)) * D + A, &q, &cost);
			}
			challenge((N_tmp - N_tmp % 3) / 3, cost[N_tmp] + (N_tmp % 3) * D + B, &q, &cost);
			if (N_tmp % 3 != 0)
			{
				challenge((N_tmp - N_tmp % 3) / 3 + 1, cost[N_tmp] + (3 - (N_tmp % 3)) * D + B, &q, &cost);
			}
			challenge((N_tmp - N_tmp % 5) / 5, cost[N_tmp] + (N_tmp % 5) * D + C, &q, &cost);
			if (N_tmp % 5 != 0)
			{
				challenge((N_tmp - N_tmp % 5) / 5 + 1, cost[N_tmp] + (5 - (N_tmp % 5)) * D + C, &q, &cost);
			}
			// challenge(1, cost[N_tmp] + D * (N_tmp - 1), &q, &cost);
		}

		cost[0] = cost[1] + D;

		for (auto j : cost)
		{
			// cout << j.first << " " << j.second << "\n";
			if (j.first == 0)
			{
				continue;
			}
			if (cost[0] / D > j.first)
			{
				cost[0] = min(cost[0], j.second + j.first * D);
			}
		}

		cout << cost[0] - 1 << "\n"; //最後に1を引く.
	}

	return 0;
}


Measured memory_bytes: 4508
// Aizu 2086: !
// 2017.9.22 bal4u@uu

#include <stdio.h>

int pm[11] = {2,3,5,7,11,13,17,19,23,29,31};
int base[38][4], exp[38][4], len[38];

int main()
{
	int n, i, j, k, a, b;
	char ms[15], *p;
	long long m, ans, x, y;

	for (i = 2; i <= 36; i++) {
		for (j = 0; j < 11; j++) {
			if ((a = pm[j]) > i) break;
			if (i % a == 0) {
				b = i, k = 0; while (b % a == 0) b /= a, k++;
				base[i][len[i]] = a, exp[i][len[i]++] = k;
			}
		}
	}
#if 0
	for (i = 2; i <= 36; i++) {
		printf("%2d:", i);
		for (j = 0; j < len[i]; j++) printf(" %d(%d)", base[i][j], exp[i][j]);
		printf("\n");
	}
#endif

	while (scanf("%d%s", &n, &ms) && n) {
		m = 0, p = ms; while (*p) {
			m *= n, m += ((*p >= 'A') ? *p-'A'+10 : *p-'0');
			p++;
		}
		for (ans = (1LL << 62), i = 0; i < len[n]; i++) {
			x = m, a = base[n][i], y = 0;
			while (x /= a) y += x;
			y /= exp[n][i];	if (y < ans) ans = y;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1748
#include<cstdio>
#include<cstring>
typedef long long LL;
const int N=2;
const int M=1e6+50;
const int mod=998244353;
struct mat{
    LL c[N][N];
    void clear(){memset(c,0,sizeof(c));}
}a,t;
mat operator * (mat a,mat b){
    mat c;c.clear();
    for(int k=0;k<N;++k)
    for(int i=0;i<N;++i)
    for(int j=0;j<N;++j)
    if(a.c[i][k]&&b.c[k][j])
    c.c[i][j]=(c.c[i][j]+1ll*a.c[i][k]*b.c[k][j]%mod)%mod;
    return c;
}
int get(long long v){
	a.c[0][0]=t.c[0][0]=t.c[0][1]=t.c[1][0]=1;
    while(v){
        if(v&1)a=a*t;
        t=t*t;v>>=1; 
    }
    return a.c[0][1];
}
int n,Ans,x,f[M],g[M],inv[M];
LL m;
int main(){
    scanf("%d%lld",&n,&m);
    Ans=get(m+2*(n-1));
	m%=mod;f[1]=g[1]=inv[1]=x=1;
	for(int i=2;i<=n;i++){
    	f[i]=(f[i-1]+f[i-2])%mod;
		g[i]=1ll*g[i-1]*m%mod;
		inv[i]=(mod-1ll*(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=n+1;i<=2*n;i++)
	f[i]=(f[i-1]+f[i-2])%mod;
	for(int i=1;i<n;i++){
		Ans=(Ans-1ll*x*f[2*n-i*2]%mod+mod)%mod;
		x=1ll*x*m%mod*inv[i]%mod;
		m++;
	}
	printf("%d\n",Ans);
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int main(){
	int a[13];a[0]=1;
	for(int i=1;i<=9;i++){
		a[i]=a[i-1]*2;
	}
	int n;
	while(cin>>n){
		bool f[10]={false};
		for(int i=9;i>=0;i--){
			if(n>=a[i]){
				f[i]=true;
				n-=a[i];
			}
		}
		vector<int> ans;
		for(int i=0;i<=9;i++){
			if(f[i]){
				ans.push_back(a[i]);
			}
		}
		for(int i=0;i<ans.size();i++){
			cout<<ans[i];
			if(i!=ans.size()-1){
				cout<<" ";
			}	
		}
		cout<<endl;
	}	
}



Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1001000000;
//01ナップサック問題その２
//アリ本
//制約
// 1 <= n <= 100
// 1 <= w_i <= 1e7
// 1 <= v_i <= 100
// 1 <= W <= 1e9


int main(){

    long long n, W; cin >> n >> W;
    vector<long long> v(n);
    vector<long long> w(n);
    for(int i = 0; i < n; i++){
        cin >> v[i] >> w[i];
    }

    //dp[i][j] := 価値がjとなるような重さの最小値
    long long dp[110][10010];
    memset(dp, INF, sizeof(dp));

    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10010; j++){
            //take
            dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);

            //no
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i <= 10010; i++){
        if(dp[n][i] <= W) ans = max(ans, i);
    }

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


Measured memory_bytes: 11704
n = gets.to_i
k = gets.to_i
ary = gets.strip.split.map(&:to_i)
ans = 0
ary.each.with_index(1) do |a, b|
  if (0-a).abs >= (k-a).abs
    ans += (k-a).abs*2
  else
    ans += (0-a).abs*2
  end
end
puts ans

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

bool is_res(int n){
    map<int,int> p;
    for(int i = 2;i*i<=n;i++){
        while(n%i == 0){
            n/=i;
            p[i]++;
        }
    }
    if(n > 1)p[n]++;
    ll res = 1;
    for(auto a:p){
        res *= a.second + 1;
    }
    if(res == 8)return true;
    return false;
}
signed main()
{   
    gearup;
    int n; cin >> n;
    ll res = 0;
    for(int i=1;i<=n;i+=2){
        if(is_res(i))res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256