akhauriyash/Code-Regression huggingface dataset:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-29 10:32
# @url:https://atcoder.jp/contests/dp/tasks/dp_c
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    nums=[list(map(int,input().split())) for i in range(n)]
    dp=[[0]*3 for i in range(n)]
    dp[0]=nums[0]
    for i in range(1,n):
        for j in range(3):
            if j==0:
                dp[i][j]=max(dp[i-1][j+1],dp[i-1][j+2])+nums[i][j]
            elif j==1:
                dp[i][j]=nums[i][j]+max(dp[i-1][j-1],dp[i-1][j+1])
            elif j==2:
                dp[i][j]=max(dp[i-1][j-1],dp[i-1][j-2])+nums[i][j]
    print (max(dp[n-1]))
if __name__ == "__main__":
    main()

Measured memory_bytes: 71596
var
   n: Integer;
   s: array of Integer;
   i: Integer;
   sum: Integer;
   min: Integer;
begin
   readln(n);
   SetLength(s, n);
   for i := 0 to n - 1 do begin
      readln(s[i]);
   end;
   sum := 0;
   min := 100;
   for i := 0 to n - 1 do begin
      sum := sum + s[i];
      if (min > s[i]) and (s[i] mod 10 <> 0) then min := s[i];
   end;
   if min = 100 then begin
      sum := 0;
   end
   else if sum mod 10 = 0 then begin
      sum := sum - min;
   end;
   writeln(sum);
end.


Measured memory_bytes: 128
n, m = map(int, input().split())
wrong_list = [0] * (n + 1)
correct_list = [0] * (n + 1)

for i in range(m):
    p, s = input().split()
    if correct_list[int(p)] == 0 and s == "WA":
        wrong_list[int(p)] += 1
    if s == "AC":
        correct_list[int(p)] = 1

for i in range(n + 1):
    if correct_list[i] == 0:
        wrong_list[i] = 0

print(str(sum(correct_list[1:])) + " " + str(sum(wrong_list[1:])))

Measured memory_bytes: 5364
def minMP(length,LIST):
    k=len(LIST)
    LONG=[]
    if k==0:
        return -1
    for i in range(1,2**k):
        long=0
        cnt=-1
        for j in range(k):
            mod=i%2
            if mod==1:
                long+=LIST[j]
                cnt+=1
            i//=2
        LONG.append([long,10*cnt])
    
    ans=float("inf")
    for ll,mp in LONG:
        ans=min(ans,mp+abs(ll-length))
    return ans 

N,a,b,c=map(int,input().split())
L=[]
Ans=float("inf")
for i in range(N):
    l=int(input())
    L.append(l)

for n in range(3**N):
    L_A=[];L_B=[];L_C=[]
    for i in range(N):
        mod=n%3
        n//=3
        if mod==0:
            L_A.append(L[i])
        elif mod==1:
            L_B.append(L[i])
        else:
            L_C.append(L[i])
    MP_A=minMP(a,L_A)
    MP_B=minMP(b,L_B)
    MP_C=minMP(c,L_C)
    
    if MP_A==-1 or MP_B==-1 or MP_C==-1:
        continue
    else:
        Ans=min(Ans,MP_A+MP_B+MP_C)

print(Ans)

Measured memory_bytes: 57176
#include<bits/stdc++.h>
#define N 10
using namespace std;
int n,a[N],z[N],ans;
string s,t;
 
void check(){
  int cp[N],cnt=0;
  for(int i=0;i<n;i++)cp[i]=a[i];
  for(int i=0;i<n;i++){
    int x=cp[i];
    if(!x)continue;
    cnt++;
    for(int j=i;j<=z[i];j++)
      cp[j]=(cp[j]-x+10)%10;
  }
  ans=min(ans,cnt);
}
 
void dfs(int x){
  if(x==n){
    check();
    return;
  }
  for(int i=x;i<n;i++){
    z[x]=i;
    dfs(x+1);
  }
}
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    cin>>s>>t;
    for(int i=0;i<n;i++)
      a[i]=((s[i]-'0')-(t[i]-'0')+10)%10;
    ans=n;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3016
#include<stdio.h>
int main(void)
{
  int k,a,b;
  scanf("%d %d %d",&k,&a,&b);
  for(int i=a;i<=b;i++){
    if(i%k==0){
      puts("OK");
      return 0;
    }
  }
  puts("NG");
  return 0;
}


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

int main()
{
  int N, T, A, H;
  int ans;
  double ans_H = 1000000;

  cin >> N >> T >> A;
  for (int i = 1; i <= N; i++)
  {
    cin >> H;
    if (abs(A - (T - H * 0.006)) < ans_H)
    {
      ans_H = abs(A - (T - H * 0.006));
      ans = i;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int x[5];
  for(int i = 0; i < 5; ++i) {
    scanf("%d", x + i);
  }
  for(int i = 0; i < 5; ++i) {
    if(x[i] == 0) {
      printf("%d\n", i + 1);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3700
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const A = parseInt(input[0].split(" ")[0]);
    const V = parseInt(input[0].split(" ")[1]);
    const B = parseInt(input[1].split(" ")[0]);
    const W = parseInt(input[1].split(" ")[1]);
    const T = parseInt(input[2].split(" ")[0]);
    const a = T*V
    const b = T*W
    const diff = A > B ? A-B : B-A
    if(diff + b <= a) console.log("YES")
    else console.log("NO")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 29628
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod = 1000 * 1000 * 1000 + 7;
int add(int a , int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a , int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
int mult(int a , int b)
{
	return a * (LL)b % mod;
}
const int MAX = 200005;
int fact[200005];
int inv[200005];
int invFact[200005];
int n , m , k;
int c(int n, int k)
{
	return mult(fact[n] , mult(invFact[k] , invFact[n - k]));
}
int main()
{
	int n , m , k;
	cin >> n >> m >> k;
    fact[0] = invFact[0] = fact[1] = invFact[1] = inv[0] = inv[1] = 1;
    
    for(int i = 2; i < MAX; i++)
    {
		fact[i] = mult(i , fact[i - 1]);
		inv[i] = mult(mod - (mod / i) , inv[mod % i]);
		
		invFact[i] = mult(invFact[i - 1] , inv[i]);
	}
	int ans = 0;
	int suma = 0;
    for(int i = 0; i < n; i++)
    {
		suma = add(suma , mult(i , m));
		ans = add(ans , mult(suma , m));
	}
	suma = 0;
	for(int i = 0; i < m; i++)
	{
		suma = add(suma , mult(n , i));
		ans = add(ans , mult(suma , n));
	}
	//cout << ans << " " << endl;
    cout << mult(ans , c(n * m - 2, k - 2));
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if (n % 2)
    {

        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < n / 2; i++)
    {
        if (s[i] != s[i + n / 2])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int N;
    long long C,K;
    long long ans = 0;
    long long last = 0;
    long long a = 0;
    vector<long long> T;
    
    cin >> N;
    cin >> C;
    cin >> K;
    
    for ( int i = 0; i < N; i++ ) {        
        long long t;
        cin >> t;
        
        T.push_back(t);
    }
    
    sort( T.begin(), T.end() );
    
    for ( auto& t : T ) {
        
        if ( !a ) {
            last = t;
            a = 1;
        }
        else {
            if ( a >= C || t-last > K ) {
                ans++;
                a = 1;
                last = t;
            }
            else {
                a++;
            }
        }
    }
    
    ans++;
    
    
    cout << ans << endl;
    
    return 0;
}

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

int main() {
  int n; cin >>n;
  string s; cin >>s;
  vector<int> le(n);
  for (int i=1; i<n; i++){
    if (s.at(i)=='E') le.at(0)++;
  }
  int sub;
  int ans = le.at(0);
  for (int i=1; i<n; i++){
    sub = 0;
    if (s.at(i)=='E') sub--;
    if (s.at(i-1)=='W') sub++;
    le.at(i) = le.at(i-1)+sub;
    if (ans > le.at(i)) ans = le.at(i);
  }
  
  
  cout <<ans;
  cout <<endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    ll N, X;
    cin >> N >> X;

    ll ans = N;
    ll a = max(N - X, X), b = min(N - X, X);

    while(b) {
        ll q = a / b;
        ll r = a % b;

        ans += (b * 2) * q;
        if (r == 0) ans -= b;

        a = b, b = r;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
	int from,to;
} edge[200001];
int n,ans1,ans2;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%lld%lld",&u,&v);
		edge[i].from=min(u,v);
		edge[i].to=max(u,v);
		ans2+=(edge[i].from)*(n-edge[i].to+1);	
	}	
	ans1=(n+2)*(n+1)*n;
	cout<<ans1/6-ans2;
	return 0;
} 

Measured memory_bytes: 6764
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	partial_sum(all(b), b.begin());
	ll tot = 0LL;
	ll ans = 0LL;
	rep(i, n + 1){
		if(i) tot += a[i - 1];
		if(tot > k) break;
		ll num = i;
		//now we need to find how many books from B we can read
		auto it = ub(all(b), k - tot);
		if(it != b.begin() && (it == b.end() || *it > (k - tot))) it--;
		if(*it <= (k - tot)) num += (it - b.begin() + 1);
		ans = max(ans, num);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 6352
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (1006)
ll n, a, b, c, d, dp[MAXN][MAXN], f[MAXN]; // groups with i people or less, j people so far
const ll MOD=1e9+7;
ll qexp(ll x,ll e) {
  if(e==0) return 1;
  ll half=qexp(x,e/2);
  half*=half;
  half%=MOD;
  if(e&1) half*=x, half%=MOD;
  return half;
}
unordered_map<int, int> mp;
ll mul_inv(ll x) { if(mp.find(x)!=mp.end()) return mp[x]; return mp[x]=qexp(x,MOD-2); }
ll P(ll n,ll k) { assert(n>=k); 
  return f[n] * mul_inv(f[n-k]) % MOD;
}
int main()
{
  FAST
  cin>>n>>a>>b>>c>>d;
  f[0]=f[1]=1; FOR(i,2,MAXN-1) f[i]=f[i-1]*i%MOD;
  vector<ll> v;
  v.pb(0);
  FOR(i,c,d) v.pb(i);
  FOR(i,0,MAXN-1) dp[i][0]=1;
  FOR(i,a,b) {
    FOR(j,1,n) {
      for(auto k:v) if(j>=i*k) {
        dp[i][j] += dp[i-1][j-i*k] * P(n-(j-i*k), i*k) % MOD * mul_inv(qexp(f[i], k)) % MOD * mul_inv(f[k]) % MOD;
        dp[i][j] %= MOD; 
      } else break;
    }
  } 
  cout<<dp[b][n];
  // cout<<(dp[b][n]-dp[a-1][n]+MOD)%MOD<<'\n';
}

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

int main(){
  	int N, cnt=0;
  	cin >> N;
  	vector<int> A(N);
  	vector<int> B(N);
  	for(int i=0; i<N; i++){
    	cin >> A[i];
    }
  
  	for(int i=0; i<N; i++){
    	B[A[i]-1] = i+1;
    }
  
  	for(int i=0; i<N; i++){
    	cout << B[i] << " ";
    }
  	cout << endl;
	return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	cout << (60 * h2 + m2) - k - (60 * h1 + m1);

	return 0;
}

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

int main(void) {
  int n, m;
  cin >> n >> m;
  
  vector<int> check(m);
  
  for (int i = 1; i <=n; i++) {
    int k;
    cin >> k;
    
    for (int j = 1; j <= k; j++) {
      int a;
      cin >> a;
      a--;
      check.at(a)++;
    }
  }
  
  int cnt = 0;
  
  for (int i = 0; i < m; i++) {
    if (check.at(i) == n) {
      cnt++;
    }
  }
  
  printf("%d", cnt);
  
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

    ll n = 100000;
    while(n*n > N){
        n--;
    }
    cout << n*n << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    int n, x, y; cin >> n >> x >> y;
    x--; y--; 
    vector<int> G[n];
    rep(i, n) {
        if (i < n - 1) G[i].push_back(i + 1);
        if (i > 0) G[i].push_back(i - 1);
    }
    G[x].push_back(y);
    G[y].push_back(x);
    
    vector<int> ans(n);
    rep(i, n) {
        vector<int> dist(n, -1);
        dist[i] = 0;
        deque<int> que;
        que.push_back(i);
        while (!que.empty()) {
            int curr = que.front();
            que.pop_front();
            ans[dist[curr]]++;
            for (int nxt : G[curr]) {
                if (dist[nxt] != -1) continue;
                que.push_back(nxt);
                dist[nxt] = dist[curr] + 1;
            }
        }
    }
    for (int i = 1; i < n; i++) cout << ans[i] / 2 << endl;
}


Measured memory_bytes: 384
# C - Half and Half
A,B,C,X,Y = map(int,input().split())

# AB ピザを買わない場合
pay1 = X*A + Y*B
# A ピザ を AB ピザで作る場合
pay2 = 10**10
if Y >= X:
    pay2 = C*2*X + B*(Y-X)
# B ピザを AB ピザで作る場合
pay3 = 10**10
if X >= Y:
    pay3 = A*(X-Y) + C*2*Y
# AB ピザで全部作る場合
pay4 = C*max(X,Y)*2
print(min(pay1,pay2,pay3,pay4))

Measured memory_bytes: 9124
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] t = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			// 時間制限区間の開始時間と終了時間
			int[] l = new int[n + 2], r = new int[n + 2];
			l[0] = r[0] = l[1] = 0;
			IntStream.range(0, n).forEach(i -> r[i + 1] = l[i + 2] = l[i + 1] + t[i]);
			r[n + 1] = l[n + 1];
			// 各区間の最大速度
			int[] v = new int[n + 2];
			v[0] = v[n + 1] = 0;
			IntStream.range(0, n).forEach(i -> v[i + 1] = scanner.nextInt());
			// 各時刻の最大速度(0.5秒刻み)
			double[] d = new double[r[n + 1] * 2 + 1];
			d[0] = 0.0d;
			System.out.println(IntStream.range(1, d.length).mapToDouble(i -> {
				d[i] = calcF(i, n, l, r, v);
				return (d[i - 1] + d[i]) / 4.0d;
			}).sum());
		}
	}

	/**
	 * 指定された時刻における走行可能の最大速度を取得する
	 * 
	 * @param index 時刻x2の値
	 * @param n     N
	 * @param l     時間帯のスタート時点
	 * @param r     時間帯のエンド時点
	 * @param v     時間帯の最大速度
	 * @return 指定された時刻における走行可能の最大速度
	 */
	private static double calcF(int index, int n, int[] l, int[] r, int[] v) {
		double time = index / 2.0d;
		return IntStream.range(0, n + 2).mapToDouble(i -> {
			if (time < l[i]) {
				return v[i] + (l[i] - time);
			} else if ((l[i] <= time) && (time <= r[i])) {
				return (double) v[i];
			} else {
				return v[i] + (time - r[i]);
			}
		}).min().getAsDouble();
	}
}


Measured memory_bytes: 52080
#include<bits/stdc++.h>
using lint=long long;
void debug_impl(){std::cerr<<'\n';}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
    template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
    template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
    template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 1
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(26,1'000'000'000);
    while(n--){
        std::string s;std::cin>>s;
        std::vector<lint>b(26);
        for(char c:s)b.at(c-'a')++;
        for(lint i=0;i<26;i++){
            if(a.at(i)>b.at(i))a.at(i)=b.at(i);
        }
    }
    for(lint i=0;i<26;i++){
        for(lint j=0;j<a.at(i);j++){
            std::cout<<char('a'+i);
        }
    }
    std::cout<<'\n';
}


Measured memory_bytes: 256
#! python3
#  solve_122C.py

N,Q = map(int,input().split())
S = input()

t = [0]*(N+1) #ACの内Aの番号を格納(?番目形式)

for i in range(N-1):
    if S[i:i+2] == "AC":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l,r  = map(int,input().split())
    print(t[r-1]-t[l-1])       

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

 using namespace std;

 int main() {
   int H, W, i, j, k;
   cin >> H >> W;
   vector<vector<char>> C(H, vector<char>(W));

   for (i = 0; i < H; i++) {
     for (j = 0; j < W; j++) {
       cin >> C.at(i).at(j);
     }
   }

   for (i = 0; i < H; i++) {
     for (k = 1; k <= 2; k++) {
       for (j = 0; j < W; j++) {
         cout << C.at(i).at(j);
         if (j == W - 1) cout << endl;
       }
     }
   }
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  
  cin >> a >> b ;
 
  if ((a * b) % 2 == 0 ) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  
}

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void GaussElimination(vl& x) {
  int N = x.size();
  int axis = 0;
  // rep(b, 60) {
  for (int b = 60; 0 <= b; b--) {
    int temp = -1;
    for (temp = axis; temp < N; temp++)
      if (((x[temp] >> b) & 1)) break;
    if (!(0 <= temp && temp < N)) continue;
    swap(x[axis], x[temp]);
    rep(i, N) if ((i != axis) && (((x[i] >> b) & 1) == 1)) x[i] ^= x[axis];
    axis++;
  }
}
/*
ll check_bit(ll x, int i) { return (x & (1LL << i)); }
vector<ll> v;
ll gaussian_elimination() {
  int n = v.size();
  int ind = 0; // Array index
  for (int bit = 60; bit >= 0; bit--) {
  // for (int bit = log2(v[0]); bit >= 0; bit--) {
    int x = ind;
    while (x < n && check_bit(v[x], bit) == 0) x++;
    if (x == n) continue; // skip if there is no number below ind where current bit is 1
    swap(v[ind], v[x]);
    for (int j = 0; j < n; j++) {
      if (j != ind && check_bit(v[j], bit)) v[j] ^= v[ind];
    }
    ind++;
  }
  ll ans = v[0];
  for (int i = 1; i < n; i++) ans = max(ans, ans ^ v[i]);
  return ans;
}
*/

void solve() {
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll x = 0;
  rep(i, n) x ^= a[i];
  dump(a);
  ll ans = x;
  dump(x);
  rep(i, n) a[i] &= ~x;
  vl v;
  rep(i, n) v.push_back(a[i]);
  // ll m = gaussian_elimination();
  GaussElimination(v);
  ll m = 0;
  rep(i, n) m ^= v[i];
  dump(a);
  dump(v);
  dump(m);
  ans += m * 2;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main() {
  int n;
  int m;
  cin >> n >> m;

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

  priority_queue<long long> q;
  for (int i = 0; i < n; i++) {
    q.push(a[i]);
  }

  for (int i = 0; i < m; i++) {
    long long tmp = q.top();
    tmp /= 2;
    q.pop();
    q.push(tmp);
  }

  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += q.top();
    q.pop();
  }
  cout << sum << endl;
}


Measured memory_bytes: 2168
#include <stdio.h>

main()
{
	int a, b;
	char op;

	while(op != '?')
	{
		scanf("%d %c %d", &a, &op, &b);
		if(op == '+')
		{
			printf("%d\n", a+b);
		}
		else if(op == '-')
		{
			printf("%d\n", a-b);
		}
		else if(op == '*')
		{
			printf("%d\n", a*b);
		}
		else if(op == '/')
		{
			printf("%d\n", a/b);
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define REP(i, n) for(int i = 0; (i) < (n); ++(i))
#define FOR(i, n) for(int i = 1; (i) <= (n); ++(i))
#define dump(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9 + 7;
// const lint LINF = 1e18;
const double eps = 0.000000001;  //もとの値の10^(-16)まで

using namespace std;

// typedef pair<int, int> P;
// priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
// cout << fixed << setprecision(10) << ans << endl;
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int dp[110][2][120];
signed main() {
  string n;
  int k2;
  cin >> n >> k2;
  int nsize = n.size();
  dp[0][0][0] = 1;
  REP(i, nsize) {
    REP(j, 2) {
      REP(k, 5) {
        if(j == 0) {
          for(int x = 0; x <= (int)(n[i] - '0'); x++) {
            if(x==0 && x == (int)(n[i] - '0')){
              dp[i + 1][0][k] += dp[i][j][k];
            }
            else if(x == (int)(n[i] - '0')){
              dp[i + 1][0][k+1] += dp[i][j][k];
            }
            else if(x==0){
              dp[i + 1][1][k] += dp[i][j][k];
            }
            else{
              dp[i + 1][1][k+1] += dp[i][j][k];
            }   
          }
        } else {
          for(int x = 0; x <= 9; x++) {
            if(x==0){
              dp[i + 1][1][k] += dp[i][j][k];
            }
            else{
              dp[i + 1][1][k+1] += dp[i][j][k];
            }
          }
        }
      }
    }
  }
  cout << dp[nsize][0][k2]+dp[nsize][1][k2] << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;
int main(){
  int n, l;
  cin >> n >> l;

  int sum = n*(l-1) + (n*(n+1))/2;
  if((l+n-1) < 0) {
    sum -= l+n-1;
  } else if(0 < l) {
    sum -= l;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int cnt = 1, a, b;
	int read;
	cin >> a;
	cin >> b;
	if (a != b) {
		cnt++;
	}
	cin >> read;
	if (a!=read&&b!=read) {
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
	string str;
	string alpha="abcdefghijklmnopqrstuvwxyz";
	int c[26]={0};
	while(1) {
		getline(cin,str);
		if(str=="") break;
		for(int i=0; i<(int)str.length(); ++i) {
			if(str[i]>='a' && str[i]<='z') {
				++c[str[i]-'a'];
			} else if (str[i]>='A' && str[i]<='Z') {
				++c[str[i]-'A'];
			}
		}
	}
	for(int i=0; i<26; ++i) {
		cout << alpha[i] << " : " << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
n = int(input())
s = []
for i in range(n):
    s.append(input())

print('AC x ' + str(s.count('AC')))
print('WA x ' + str(s.count('WA')))
print('TLE x ' + str(s.count('TLE')))
print('RE x ' + str(s.count('RE')))

Measured memory_bytes: 79208
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	int check = a[0], ans = 0;
	for (int i = 0; i < n; ++i) {
		if (check >= a[i]) {
			++ans;
			check = min(check,a[i]);
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val s = readLine()?.toLong() ?: return
    val sList = mutableListOf<Long>()
    var tmp = s
    while (tmp > 0) {
        sList += (tmp % 10)
        tmp /= 10
    }

    sList.reverse()

    var total = 0L
    val bit = 2 shl sList.size - 2

    for (flg in 1..Math.pow(2.0, sList.size - 1.0).toInt()) {
        val numList = mutableListOf<Long>()
        var currentNum = 0L
        for (i in 0 until sList.size) {
            currentNum *= 10
            currentNum += sList[i]
            if (flg.and(bit shr i + 1) == bit shr i + 1) {
                numList += currentNum
                currentNum = 0
            }
        }
        numList += currentNum
        total += numList.sum()
    }
    println(total)
}

Measured memory_bytes: 31804
# C - たくさんの数式 / Many Formulas

import itertools

S = input()

ans_list = []

for plus_pattern in list(itertools.product(["","+"], repeat = len(S)-1)):

    formula = ""
    for idx in range(len(S)-1):
        formula += S[idx]
        formula += plus_pattern[idx]

    formula += S[-1]
    ans_list.append(eval(formula))

print(sum(ans_list))

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

void skip(string &str,int &i){
  if(str[i]!='(')return;
  string res;
  int cnt=1;i++;
  while(1) {
    if(str[i]=='(')cnt++;
    if(str[i]==')')cnt--;
    if(!cnt)break;
    res+=str[i++];
  }
}


int num[1<<8];
vector <S> mem;
map <string,int> M;
void calc(char ch,S a,S b, S &res){
  S::iterator i,j;
  for(i=a.begin();i!=a.end();i++)
    for(j=b.begin();j!=b.end();j++){
      int I=*i,J=*j,c=0;
      if(ch=='+') c=I+J;
      else if(ch=='-') c=I-J;
      else if(ch=='*') c=I*J;
      else if(ch=='/'){
	if(!J)continue;
	c=I/J;
      }
      res.insert(c);
    }
}

S solve(string str){
  S res;
  if(str.size()==1){res.insert(num[str[0]]);return res;}
  if(M.count(str))return mem[M[str]];
  int a=0;skip(str,a);
  if(a==str.size()-1)return solve(str.substr(1,str.size()-2));

  string A,B;
  for(int i=0;i<str.size()-1;i+=2){
    skip(str,i);
    if(i>=str.size()-1)break;
    string A=str.substr(0,i+1),B=str.substr(i+2,str.size()-i-2);
    calc(str[i+1],solve(A),solve(B),res);
  }
  M[str]=mem.size();
  mem.push_back(res); 
  return mem[M[str]];
}

int main(){
  while(1){
    string str;
    cin>>str;
    if(str=="#")break;
    mem.clear(),M.clear();
    string siki;
    char ch='A';
    for(int i=0;i<(int)str.size();){
      int b=0;
      while('0'<=str[i]&&str[i]<='9') b=b*10+str[i++]-'0';
      if(b) num[ch]=b,siki+=ch++;
      else siki+=str[i++];
    }
    cout <<solve(siki).size()<<endl;
  }
  return 0;
}

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

using namespace std;

int h , w , k;
char grid[8][8];

int can(int a , int b){
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a & (1 << i)) continue;
            if(b & (1 << j)) continue;
            cnt += grid[i][j] == '#';
        }
    }
    return cnt;
}

int main(){
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> grid[i][j];
        }
    }
    int cnt = 0;
    for(int msk1 = 0; msk1 <= ( (1 << h) - 1); msk1++){
        for(int msk2 = 0; msk2 <= ((1 << w) - 1); msk2++){
            if(can(msk1 , msk2) == k){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3632
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int n, q;
    cin >> n >> q;

    string str;
    cin >> str;

    int cnt[n + 1] = {};

    FOR(i, 1, n + 1) {
        cnt[i] = cnt[i - 1];
        if (i < n && str[i - 1] == 'A' && str[i] == 'C') {
            cnt[i]++;
            cnt[i + 1] = cnt[i];
            i++;
        }
    }

    FOR(i, 1, n + 1) {
        fprintf(stderr, "%d ", cnt[i]);
    }
    fprintf(stderr, "\n");

    int l, r;
    REP(i, q) {
        scanf("%d%d", &l, &r);
        OUT(cnt[r - 1] - cnt[l - 1]);
    }

    return 0;
}



Measured memory_bytes: 1408
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int arr[26];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    string str;
    cin>>str;
    for(int i=0;i<str.size();i++)
        arr[str[i]-'a']++;
    bool fl = 1;
    for(int i=0;i<26;i++)
        if(arr[i]%2){
            fl = 0;
            break;
        }
    if(fl)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <iomanip>
#include <cmath>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    string S;
    cin >> S;
    if(S <= "2019/04/30"){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}


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

int main(){
int a[5],k;
cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
(a[4] - a[0] > k)? cout << ":(\n" : cout << "Yay!\n";
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  dp = [[0]*13 for _ in range(len(S)+1)]
  dp[0][0] = 1

  MOD = 1_000_000_007
  for i in range(1, len(S)+1):
    if S[i-1] == '?':
      for s in range(10):
        for j in range(13):
          dp[i][(10*j + s) % 13] += (dp[i-1][j] % MOD)
    else:
      for j in range(13):
        dp[i][(10*j + int(S[i-1])) % 13] += (dp[i-1][j] % MOD)

  print(dp[len(S)][5] % MOD)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 95976
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;

const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {-1, 0, 1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}

ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 3e5 + 5;
const double PI = acos(-1.0);
const ll mod = 998244353;
/*************************************************************************/

ll k, n;
ll val[maxn];
void solve() {
    SLLA(k);
    SLLA(n);
    REPP(i,1,n) {
        SLLA(val[i]);
    }
    ll ans = k;
    REPP(i,2,n) {
        ans = min(ans, k - (val[i] - val[i-1]));
    }
    ans = min(ans, k - (val[1] - (val[n] - k)));
    printf("%lld\n", ans);
}

int main()
{
#ifndef ONLINE_JUDGE
  //freopen("/Users/chong_wang/Desktop/ev/Code/i.txt", "r", stdin);
  //freopen("o.txt", "w", stdout);
#endif
     solve();
  return 0;
}





Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	char* buf = new char[N+1];

	set<ull> S;

	scanf("%s",buf);

	ull* P1 = new ull[N+1];

	P1[0] = 1;

	for(int i = 1; i <= N; i++){
		P1[i] = P1[i-1]*MOD;
	}

	ull* HASH = new ull[N+1];

	HASH[0] = 0;

	for(int i = 1; i <= N; i++){
		HASH[i] = buf[i-1]+HASH[i-1]*MOD;
	}

	int L = 1,R = 1;
	ull hashValue;
	char order[10];

	for(int loop = 0; loop < M; loop++){
		scanf("%s",order);

		if(order[0] == 'L' && order[1] == '+'){
			L++;
		}else if(order[0] == 'L' && order[1] == '-'){
			L--;
		}else if(order[0] == 'R' && order[1] == '+'){
			R++;
		}else{ //order[0] == 'R' && order[1] == '-';
			R--;
		}

		hashValue = HASH[R] - HASH[L-1]*P1[R-(L-1)];

		S.insert(hashValue);
	}

	printf("%d\n",S.size());

	return 0;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
char str[200];
int gs(int pos,int len){
    bool a1[26],a2[26];
    memset(a1,0,sizeof(a1));
    memset(a2,0,sizeof(a2));
    for(int i=0;i<pos;i++){
        a1[str[i]-'a'] = true;
    }
    for(int i=pos;i<len;i++){
        a2[str[i]-'a'] = true;
    }
    int cnt = 0;
    for(int i=0;i<26;i++){
        if(a1[i]&&a2[i]) cnt++;
    }
    return cnt;
}
int main()
{
    int n;
    while(~scanf("%d",&n)){

        scanf("%s",str);
        int ans = -0x3f3f3f3f3f;
        for(int i=0;i<=n;i++){
            ans = max(ans,gs(i,n));
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))

min_value = arr[0]
max_value = arr[0]
sum = 0
for i in range(n):
	current = arr[i]
	min_value = min(min_value, current)
	max_value = max(max_value, current)
	sum += current

print(str(min_value) + ' ' + str(max_value) + ' ' + str(sum))



Measured memory_bytes: 6596
#include<stdio.h>

int main()
{
	double num;
	double Menseki, Ensyu;
	double Ensyuritu = 3.141592653589;
	double dRet = 0;
	double dRet2 = 0;
	scanf("%lf",&num);

	Menseki = num * num * Ensyuritu;
	Ensyu = 2 * num * Ensyuritu;

	printf("%.6f %.6f\n",Menseki,Ensyu);
	return 0;
}


Measured memory_bytes: 2036
#include <stdio.h>
#include <math.h>

int main(){
  double x1,x2,y1,y2,x,y,re;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  x=x2-x1;
  y=y2-y1;
  re=sqrt(x*x+y*y);
  printf("%f\n",re);

  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>
#include <map>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
    // 整数の入力
    ll H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    cout << max((H2 * 60 + M2) - (H1 * 60 + M1) - K,0LL) <<endl;

    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main(){
     vector<pair<long long, long long>> pairs;
     int N,M,j;
     long long sum,tempA,tempB;
     long long result;
     cin >> N >> M;
     for(int i = 0; i < N; i++){
          cin >> tempA >> tempB;
          pairs.push_back(make_pair(tempA,tempB));
     }
     sort(pairs.begin(),pairs.end());
     sum = 0;
     result = 0;
     j = 0;
     for(j = 0; sum + pairs[j].second <= M; j++){
          result += pairs[j].first*pairs[j].second;
          sum += pairs[j].second;
     }
     result += pairs[j].first*(M - sum);
     cout << result << endl;
     return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, n){
      cin >> a[i];
   }
   bool isin = true;
   rep(i, n){
      if(a[i] % 2 == 0){
         if(a[i] % 3 == 0) continue;
         if(a[i] % 5 == 0) continue;
         isin = false;
      }
   }
   if(isin) cout << "APPROVED" << endl;
   else cout << "DENIED" << endl;
   return 0;
}   

Measured memory_bytes: 256
A,B,C = [int(i) for i in input().split()]
list = [A,B,C]
go = 0
nana = 0
for i in list:
  if i == 5:
    go += 1
  if i == 7:
    nana += 1

if go == 2 and nana == 1:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	int n;double d;
	cin>>n>>d;
	int ans=0;
	rep(i,1,n){
		double x,y;cin>>x>>y;
		if(x*x+y*y<=d*d){
			ans+=1;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

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

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

int main()
{
    string o,e,ans;
    cin >> o >> e;
    rep(i, o.size()){ans += o[i];if(i < e.size())ans += e[i];}
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256