akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	map<char, ll> mp;
	rep(i, n) {
		string s;
		cin >> s;
		char ss = s[0];
		if (ss == 'M'
			|| ss == 'A'
			|| ss == 'R'
			|| ss == 'C'
			|| ss == 'H'
			)
		{
			mp[ss]++;
		}
	}
	ll ans = 0;
	string sr = "MARCH";
	repi(i, 0, 5) {
		repi(j, i + 1, 5) {
			repi(k, j + 1, 5) {
				ans += mp[sr[i]] * mp[sr[j]] * mp[sr[k]];
			}
		}
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int mod=1e9+7;
string s;
int ans;
int main(){
	 cin>>s;
	 if(s == "SAT")ans = 1;
	 else if(s=="MON"){
	 	ans = 6;
	 }
	 else if(s=="TUE"){
	 	ans = 5;
	 }
	 else if(s=="WED"){
	 	ans = 4;
	 }
	 else if(s=="THU"){
	 	ans = 3;
	 }
	 else if(s=="FRI"){
	 	ans = 2;
	 }
	 else if(s=="SUN"){
	 	ans = 7;
	 }
	 cout<<ans;
 }

Measured memory_bytes: 3596
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

int H, W;
int mat[202][202];
int ans;
int main()
{
	scanf("%d %d", &H, &W);

	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			scanf("%d", &mat[i][j]);
		}
	}

	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			for(int k = 0; k < 10; k++) {
				mat[j][k] = min(mat[j][k], mat[j][i] + mat[i][k]);
			}
		}
	}

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			int temp;
			scanf("%d", &temp);
			if(temp != -1){
				ans += mat[temp][1];
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}
/*
	Powered by Buggy Plugin
*/

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);




void solve(int testCase){

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

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

    vector < int > dp(n , 2e9);
    dp[0] = 0;
    for(int i = 0 ; i < n ; i ++){
            for(int j = i+1 ; j <= i + k && j < n ; j ++){
                        dp[j] = min(dp[j] , dp[i] + abs(a[i] - a[j]));
            }
    }

    printf("%d\n" , dp[n-1]);

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int x,n;
    cin >> x >> n;
    map<int,int>mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    int dist = 1000;
    int ans = -1;
    for(int i = 0;i<=101;i++) {
        int tmp_dist = abs(x-i);
        if(dist>tmp_dist && mp[i] == 0) {
            dist = tmp_dist;
            ans = i;
        }
    }
    cout << ans << endl;
}



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

#define MAX_N 1000
#define MAX_D 5000

using namespace std;

int n;

int v[MAX_N + 1];
int sum[MAX_N + 1];

int k;
int lst[MAX_N + 1];
int nod[MAX_N + 1];
int urm[MAX_N + 1];

bool dp[2][MAX_D + 1];

void add(int a, int b)
{
    k ++;

    nod[k] = b;
    urm[k] = lst[a];

    lst[a] = k;
}

void dfs(int a)
{
    int dmin = 0;
    int p, u;
    for(p = lst[a]; p != 0; p = urm[p])
    {
        u = nod[p];
        dfs(u);
        sum[a] += sum[u];

        dmin += min(v[u], sum[u] - v[u]);
    }

    if(v[a] < dmin)
    {
        printf("IMPOSSIBLE\n");

        exit(0);
    }

    int ant = 1, cr = 0, aux;
    int i;
    for(i = 0; i <= v[a]; i ++)
        dp[ant][i] = dp[cr][i] = 0;

    dp[ant][0] = 1;
    int j;
    for(p = lst[a]; p != 0; p = urm[p])
    {
        u = nod[p];

        for(j = 0; j <= v[a]; j ++)
        {
            if(dp[ant][j] != 0)
            {
                if(j + v[u] <= v[a])
                    dp[cr][j + v[u]] = 1;

                if(j + sum[u] - v[u] <= v[a])
                    dp[cr][j + sum[u] - v[u]] = 1;
            }
        }

        aux = cr;
        cr = ant;
        ant = aux;
    }

    int gcr = v[a];
    while(gcr > 0 && dp[ant][gcr] == 0)
        gcr --;

    sum[a] += v[a] - gcr;
}

int main()
{
    scanf("%d", &n);
    int i, a;
    for(i = 2; i <= n; i ++)
        scanf("%d", &a), add(a, i);
    for(i = 1; i <= n; i ++)
        scanf("%d", &v[i]);

    dfs(1);

    printf("POSSIBLE\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
#define MAX_W 100
#define MAX_H 100
char farm[MAX_W][MAX_H];
int W, H;
const int direction[4][2] = {
	{ -1, 0 },
	{ 1, 0 },
	{ 0, -1 },
	{ 0, 1 },
};
 
void dfs(const int& x, const int& y, const char tree)
{
	farm[x][y] = 'x';
	for (int i = 0; i < 4; ++i)
	{
		int nx = x + direction[i][0];
		int ny = y + direction[i][1];
		if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)
		{
			dfs(nx, ny, tree);
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	while (cin >> H >> W, W > 0)
	{
		int res = 0;
		int x, y;
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				cin >> farm[x][y];
			}
		}
 
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				if (farm[x][y] != 'x')
				{
					dfs(x, y, farm[x][y]);
					++res;
				}
			}
		}
		cout << res << endl;
	}
 
	return 0;
}


Measured memory_bytes: 3772
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;



int main(void) {

    int N; cin>>N;
    vector<int> L(N);
    for (int i = 0; i < N; ++i) {
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    ll ans = 0;
    for (int i = 0; i < N-2; ++i) {
        for (int j = i+1; j < N-1; ++j) {
            int xy = L[i]+L[j];
            int l=j+1, r=N;
            int maxindex = j;
            while (l<r){
                int midkey = (r+l)/2; //
                if(L[midkey] < xy){
                    maxindex = max(maxindex, midkey);
                    l = midkey+1;
                }else r = midkey;
            }
            ans += maxindex-j;
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

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

    vector<ll> vdivisor;
    ll mloopmax = sqrt(m) + 1;
    
    reps(div, 1, mloopmax){
        if(m % div == 0){
            vdivisor.push_back(div);
            vdivisor.push_back(m/div);
        }
    }

    // for(auto x : vdivisor){
    //     cout << x << endl;
    // }

    sort(vdivisor.begin(), vdivisor.end(), greater<ll>());

    rep(i, vdivisor.size()){
        if(n * vdivisor[i] <= m){
            cout << vdivisor[i];
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
g=[[0]*(W+2)]+[[0]+[(i=="#")*1 for i in list(input())]+[0] for _ in range(H)]+[[0]*(W+2)]
ans="Yes"
for i in range(1,H+1):
  for j in range(1,W+1):
    t=0
    if g[i][j]==0:
      continue
    if g[i-1][j]==1:
      t+=1
    if g[i+1][j]==1:
      t+=1
    if g[i][j-1]==1:
      t+=1
    if g[i][j+1]==1:
      t+=1
    if t==0:
      ans="No"
      break
print(ans)


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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;

    }

    public static string Solve()
    {
        string s = Console.ReadLine();
        string key = "keyence";
        int k = 0;
        for(int i = 0;i<7;i++)
        {
            if(s[i] != key[i])
            {
                k = i;
                break;
            }
        }
        int l = s.Length;
        for(int i = k;i<7;i++)
        {
            if (s[l - 7 + i] != key[i])
            {
                return "NO";
            }
        }

        return "YES";
    }
}


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

int h,w,k;
char maze[1010][1010];
int sh,sw;
int d[1010][1010];
int inf = 1e9;
int dh[4] = {0,0,1,-1};
int dw[4] = {1,-1,0,0};

int main() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) cin >> maze[i];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (maze[i][j] == 'S') {
                sh = i;
                sw = j;
            }
            d[i][j] = inf;
        }
    }
    queue<pair<int,int>> q;
    q.push({sh,sw});
    d[sh][sw] = 0;
    while (!q.empty()) {
        pair<int,int> p = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int th = p.first + dh[i];
            int tw = p.second + dw[i];
            if (th < 0 || th >= h) continue;
            if (tw < 0 || tw >= w) continue;
            if (maze[th][tw] == '#') continue;
            if (d[th][tw] != inf) continue;
            d[th][tw] = d[p.first][p.second] + 1;
            q.push({th,tw});
        }
    }

    int ans = inf;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (d[i][j] == inf) continue;
            ans = min(ans, (max(d[i][j] - k, 0) + k - 1 + min(min(i,h - i - 1),min(j,w - j - 1))) / k + 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int N, C;
int A[401], B[401];
long long ptable[401][401]; //dp a, b = 1^b + ... + a^b
long long dp[401][401];
const int MOD = 1e9+7;
void init()
{
    for(int b=0; b<=400; ++b)
    {    
        for(int a=1; a<=400; ++a)
        {
            long long x = 1;
            for(int i=0; i<b; ++i)
                x = (x*a)%MOD;
            ptable[a][b] = (ptable[a-1][b] + x) %MOD;
        }
    }
    return;
}
int main()
{
    init();
    scanf("%d%d", &N, &C);
    for(int i=0; i<N; ++i) scanf("%d", A+i+1);
    for(int i=0; i<N; ++i) scanf("%d", B+i+1);
    dp[0][0] = 1;
    for(int k=1; k<=N; ++k)
    {
        for(int c=0; c<=C; ++c)
        {
            dp[k][c] = 0;
            for(int ak=0; ak<=c; ++ak)
            {
                dp[k][c] += dp[k-1][c-ak] * (MOD + ptable[B[k]][ak] -ptable[A[k]-1][ak]);
                dp[k][c] %= MOD;
            }   
        }
    }
    printf("%lld\n", dp[N][C]);
    return 0;
}

Measured memory_bytes: 2816
#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(v) v.begin(), v.end()

int main() {
  std::cout << std::fixed << std::setprecision(20);
  string T;
  cin >> T;
  string s = T;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '?') cout << "D";
    else cout << s[i];
  }
  cout << endl;



  
}

Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    while (cin >> N, N)
    {
        int dp[30] = {0};

        dp[0] = 1; dp[1] = 1; dp[2] = 2;

        for(int i = 3; i <= N; i++)
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];

        cout << 1 + dp[N] / 3650 << endl; 
    }
}


Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s1,s2,s3;
    
    cin>>s1>>s2>>s3;
    
    cout<<s1[0]<<s2[1]<<s3[2]<<endl;
    return 0;
    
    
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.first,", ",x.second,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int N, L;
vi arr;

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

	cin >> N >> L;
	arr.resize(N);
	F0R(i, N) cin >> arr[i];


	F0R(i, N - 1) {
		if (arr[i] + arr[i + 1] >= L) {
			print("Possible");
			F0R(j, i) print(j+1);
			ROF(j, i + 1, N - 1) print(j+1);
			print(i+1);
			return 0;
		}
	}
	print("Impossible");
	
}

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

int N,M;
string board[60];
string pattern[60];

bool match(int x, int y){
  int i,j;
  for(i = 0; i < M; i++)
    for(j = 0; j < M; j++)
      if(board[x + i][y + j] != pattern[i][j])
        return false;
      return true;  
}
  
int main(){
 cin >> N >> M;
 int i,j;
 for(i = 0; i < N; i++) cin >> board[i];
 for(i = 0; i < M; i++) cin >> pattern[i];
 
 bool found = false;

 for(i =0; i <= N - M; i++)
   for(j = 0; j <= N - M; j++)
     if(match(i,j))
       found = true;

       
 cout << (found? "Yes" : "No") << endl;

 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

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

template <class T>
class SegmentTree {
    long long n; // 葉の数
    vector<T> data;  // データを格納する配列
    T def;  // 初期値（単位元）
    function<T(T, T)> operation;  // 区間クエリで使う処理
    function<T(T, T)> update;  // 点更新で使う処理

    T _query(long long a, long long b, long long k, long long l, long long r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return data[k];  // a,l,r,bの順で含まれる
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)>>1);
            T c2 = _query(a, b, 2*k+2, (l+r)>>1, r);
            return operation(c1, c2);
        }
    }

public:
    SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
            n = 1;
            while (n < _n) n<<=1;
            data = vector<T>(2*n-1, def);
        }
    
    void change(long long i, T x) {
        i += n-1;
        data[i] = update(data[i], x);
        while (i>0) {
            i = (i-1)>>1;
            data[i] = operation(data[i*2+1], data[i*2+2]);
        }
    }

    T query(long long a, long long b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](long long i) {
        return data[i+n-1];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll h(n), a(n);
    REP(i, n) cin >> h[i];
    REP(i, n) cin >> a[i];
    SegmentTree<ll> seg(n+1, 0LL, 
                        [](ll a, ll b){return max(a, b);},
                        [](ll a, ll b){return b;});
    REP(i, n) {
        ll tmp = seg.query(0, h[i]);
        seg.change(h[i], tmp+a[i]);
    }
    cout << seg.query(0, n+1) << '\n';
    return 0;
}


Measured memory_bytes: 7424
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var length1 = input[0];
        var length2 = input[1];
        var str1 = ReadLine();
        var str2 = ReadLine();
        var g = Calculation.GCD(length1, length2);
        for(var i = 0; i <g; i++)
        {
            if (str1.Substring(i*(length1/g), 1) != str2.Substring(i*(length2/g), 1)) { WriteLine(-1);return; }
        }
        WriteLine(Calculation.LCM((long)length1,(long)length2));
    }
}
public class Calculation
{
   public static int LCM(int num1, int num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static long LCM(long num1, long num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }
  
  public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static long GCD(long num1, long num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }
}

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

#define ll long long int 
#define pii pair<int, int>
#define INF 0x3f3f3f3f
#define fi first
#define se second
#define f(n) for(int i = 0; i < n; i++)
#define f2(n) for(int i = 1; i <= n; i++)
#define debug(x) if(on)cout << x << endl
#define on true
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back


int main(){

	ll a, b, c, k;

	cin >> a >> b >> c >> k;


	if(k < a){
		cout << k << endl;
		return 0;
	}

	k -= a;

	k -= b;

	if(k < 0){
		cout << a << endl;
		return 0;
	}
	

	cout << a - k << endl;

return 0;

}


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

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

  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j <= i; j++) tmp += A.at(j);
    for (int j = i; j < N; j++) tmp += B.at(j);
    ans = max(ans, tmp);
  }

  cout << ans << "\n";
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll a[MAXN], b[MAXN], c[MAXN];
ll dp[MAXN][3];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i + 1] >> b[i + 1] >> c[i + 1];

    return true;
}

void solve() {
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 10496
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int N = 1e5+7;
void dfs(int now,int n,string ans,int k){
	if(now == n){
		cout << ans << "\n";
		return ;
	}
	for(int i = 0;i <= k;++i) dfs(now+1,n,ans+(char)('a'+i),max(k,i+1));
	return ;
}
int main() {
    int n;
	cin >> n;
	dfs(0,n,"",0);
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

int main(){
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll> >AB(N);
	rep(i, N) {
		cin >> AB[i].first >> AB[i].second;
	}

	sort(AB.rbegin(), AB.rend());

	//cost
	priority_queue<ll> Q;

	ll ans = 0;
	for(ll i = 1; i <= M; i++) {
		while(AB.size() > 0 && AB.back().first <= i) {
			Q.push(AB.back().second);
			AB.pop_back();
		}

		if(!Q.empty()) {
			ans += Q.top();
			Q.pop();
		}
	}

	cout << ans << endl;


}


Measured memory_bytes: 5884
package main

import (
	"fmt"
)

type node struct {
	name     int
	may_Cir  bool
	sta_list []int //the list of this node start to others node
	end_list []int //the list of others node end with this node
}

func main() {
	var nodes_sum, edges_sum, sta_temp, end_temp int
	fmt.Scanf("%d %d", &nodes_sum, &edges_sum)
	nodes := make([]node, nodes_sum, 1000)
	for i := 0; i < edges_sum; i++ {
		fmt.Scanf("%d %d", &sta_temp, &end_temp)
		nodes[sta_temp].name = sta_temp
		nodes[sta_temp].sta_list = append(nodes[sta_temp].sta_list, end_temp)
		nodes[end_temp].end_list = append(nodes[end_temp].end_list, sta_temp)
	}
	for i := 0; i < nodes_sum; i++ {
		if len(nodes[i].end_list) > 0 && len(nodes[i].sta_list) > 0 {
			nodes[i].may_Cir = true
		} else {
			nodes[i].may_Cir = false
		}
	}
	for i := 0; i < nodes_sum; i++ {
		var passed_arr []int
		if findCir(nodes, passed_arr, i, i) == 1 {
			fmt.Println("1")
			return
		} else {
			nodes[i].may_Cir = false
		}
	}
	fmt.Println("0")
}
func findCir(nodes []node, passed_arr []int, aim int, n int) int {
	if nodes[n].may_Cir {
		//path.Push(n)
		if isExist(passed_arr, n) {
			return 1
		}
		passed_arr = append(passed_arr, n)
		for j := 0; j < len(nodes[n].end_list); j++ {
			if nodes[n].end_list[j] == aim {
				return 1
			} else {
				if aim < nodes[n].end_list[j] {
					if 1 == findCir(nodes, passed_arr, aim, nodes[n].end_list[j]) {
						return 1
					}
				}
			}
		}
	}
	return 0
}
func isExist(arr []int, aim int) bool {
	for e := range arr {
		if arr[e] == aim {
			return true
		}
	}
	return false
}



Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int x,a,b; cin >> x >> a >> b;
	cout << (x-a)%b << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <cstring>
using namespace std;
#define MAXN 100000
#define NIL -1

int n;
vector<int> G[MAXN];
int color[MAXN];

void dfs(int r, int c)
{
	stack<int> S;
	S.push(r);
	color[r] = c;
	while(!S.empty())
	{
		int u = S.top();
		S.pop();
		for(int i = 0; i < G[u].size(); i++)
		{
			int v = G[u][i];
			if(color[v] == NIL)
			{
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor()
{
	int cid = 1;
	memset(color, -1, sizeof(color));
	for(int i = 0; i < n; i++)
	{
		if(color[i] == NIL)
		{
			dfs(i, cid++);
		}
	}
	
}

int main()
{
	int m, q;
	scanf("%d%d", &n, &m);
	int s, t;
	for(int i = 0; i < m; i++)
	{
		
		scanf("%d%d", &s, &t);
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	scanf("%d", &q);
	for(int i = 0; i < q; i++)
	{
		scanf("%d%d", &s, &t);
		if(color[s] == color[t])
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 8488
from collections import Counter

N = int(input())
A = map(int, input().split())
MOD = 10**9+7
ac = Counter(A)

ans = 0
if N % 2 != 0:
    if ac[0] != 1:
        print(0)
        exit(0)
    for i in range(2, N, 2):
        if ac[i] != 2:
            print(0)
            exit(0)
    ans = 2**((N-1)//2)
else:
    for i in range(1, N, 2):
        if ac[i] != 2:
            print(0)
            exit(0)
    ans = 2**(N//2)
print(ans % MOD)


Measured memory_bytes: 22160
a, b, k = map(int, input().split())
if b-a+1 < 2*k:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int A,B,C;
int main(){
  cin>>A>>B>>C;
  int res=0;
  if(A==B&&B==C&&A%2==0) prin(-1);
  else{
    while(A%2==0&&B%2==0&&C%2==0){
      int temA=A,temB=B;
      A=B/2+C/2;
      B=temA/2+C/2;
      C=temA/2+temB/2;
      res++;
    }
    prin(res);
  }
  
  return 0;
}


Measured memory_bytes: 256
h, w = gets.chomp.split(" ").map(&:to_i)
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = Array.new(h).map{Array.new(w, 0)}
pointer = 0
count = a[pointer]
h.times do |row|
    w.times do |column|
        ans[row][column] = pointer + 1
        count -= 1
        if count <= 0 then
            pointer += 1
            count = a[pointer]
        end
    end
    if row % 2 != 0 then
        ans[row].reverse!
    end
end

ans.each do |res|
    puts res.join(" ")
end

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct S {
    int a, b, c;
};

const int UNDEFINED = 1e9;

int N, Ma, Mb;
vector<S> abc;
S total;
vector<vector<vector<int>>> dp;
int ans = UNDEFINED;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> Ma >> Mb;
    abc.resize(N);
    
    rep(i, N) {
        cin >> abc[i].a >> abc[i].b >> abc[i].c;
        total.a += abc[i].a;
        total.b += abc[i].b;
        total.c += abc[i].c;
    }
    
    dp.resize(N);
    
    rep(i, N) {
        dp[i].resize(total.a + 1);
        
        rep(ii, total.a + 1) {
            dp[i][ii].resize(total.b + 1, UNDEFINED);
        }
    }
    
    rep(i, N) {
        rep(ii, sz(dp[i])) {
            rep(iii, sz(dp[i][ii])) {
                if (i == 0) {
                    if ((ii == abc[i].a) && (iii == abc[i].b)) {
                        dp[i][ii][iii] = abc[i].c;
                    }
                }
                else {
                    dp[i][ii][iii] = dp[i - 1][ii][iii];
                    
                    if ((ii == abc[i].a) && (iii == abc[i].b)) {
                        dp[i][ii][iii] = min(dp[i][ii][iii], abc[i].c);
                    }
                    else if ((ii > abc[i].a) && (iii > abc[i].b)) {
                        dp[i][ii][iii] = min(dp[i][ii][iii], dp[i - 1][ii - abc[i].a][iii - abc[i].b] + abc[i].c);
                    }
                }
            }
        }
    }
    
    rep(i, N) {
        reps(ii, 1, sz(dp[i])) {
            reps(iii, 1, sz(dp[i][ii])) {
                if (((double)Ma / Mb) == ((double)ii / iii)) {
                    ans = min(ans, dp[i][ii][iii]);
                }
            }
        }
    }
    
    cout << ((ans == UNDEFINED) ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n, m := readI(), readI()
	uf := newUF(n)
	for i := 0; i < m; i++ {
		uf.unite(readI()-1, readI()-1)
	}
	fmt.Println(-min(uf.d))
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

//Union-Find
type unionFind struct {
	d []int
}

func newUF(n int) *unionFind {
	d := make([]int, n)
	for i := range d {
		d[i] = -1
	}
	u := unionFind{d}
	return &u
}

func (u *unionFind) root(a int) int {
	if u.d[a] < 0 {
		return a
	}
	u.d[a] = u.root(u.d[a])
	return u.d[a]
}

func (u *unionFind) unite(a, b int) {
	ar, br := u.root(a), u.root(b)
	if ar == br {
		return
	}
	if -u.d[ar] < -u.d[br] {
		ar, br = br, ar
	}
	u.d[ar] += u.d[br]
	u.d[br] = ar
}

func (u *unionFind) isSame(a, b int) bool {
	return u.root(a) == u.root(b)
}

func (u *unionFind) size(a int) int {
	return -u.d[u.root(a)]
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 5852
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()
P, Y = [], []
for i in range(M):
    j, k = LI()
    P.append(j)
    Y.append(k)

#  N = 10**5
#  M = 10**5
#  P, Y = [], []
#  for i in range(M):
#      P.append(10)
#      Y.append(i*100)

city_records = [[]for i in range(10**6)]
for p, y in zip(P, Y):
    #  print('p,y', p, y)
    #  print('city_records[p]', city_records[p])
    city_records[p].append(y)

#  print(city_records)

for i in range(len(city_records)):
    if city_records[i] == []:
        continue
    city_records[i].sort()

#  print(city_records)

for p, y in zip(P, Y):
    #  order = (city_records[p].index(y)) + 1
    order = bisect.bisect_left(city_records[p], y) + 1
    print(str(p).zfill(6) + str(order).zfill(6))


Measured memory_bytes: 90736
nk = input(' ')
n = int(nk.split()[0])
k = int(nk.split()[1])
alist = list(map(int,input('').split()))

loop_start=0
loop_end=0
root = [1]
next_val=1
flag=[True]*n
flag[0]=False # 踏んだかどうか判定機
a=1
for i in range(k):
    a = alist[a-1]
    if flag[a-1]: # 踏んでたらそこでブレイク
        root.append(a)
        flag[a-1]=False # 踏んだらFalseに
    else:
        break

#print("{} {}->{}".format(root,loop_start,loop_end))

loop_start=root.index(a)
loop_end=len(root)
step=(k-loop_start)%(len(root)-loop_start)
#print("step:({}-{})%({} - {})={}".format(k,loop_start,loop_end,loop_start,step))
#print("root[{}+{}]={}".format(loop_start,step,root[loop_start+step]))
print(root[loop_start+step])

Measured memory_bytes: 32340
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
nums = LI()


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


ret = nums[0]
while len(nums) > 1:
    ret = gcd(ret, nums.pop(-1))



print(ret)

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

int main() {
    int n;
    cin >> n;
    int value, count = 1, max = 1;
    for(int i = 0; i < n; i++) {
        cin >> value;
        if(value == 1) {
            count++;
        } else if (value == 0) {
            if(count > max) {
                max = count;
            }
            count = 1;
        }
    }
    if (count > max) {
        max = count;
    }
    cout << max << endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int eval(string S, string P){
  int N = S.size();
  while (P.size() != 4){
    P = '0' + P;
  }
  for (int i = 0; i < N; i++){
    if ('a' <= S[i] && S[i] <= 'd'){
      S[i] = P[S[i] - 'a'];
    }
  }
  stack<int> st;
  for (int i = 0; i < N; i++){
    stack<int> st2 = st;
    if ('0' <= S[i] && S[i] <= '9'){
      st.push(S[i] - '0');
    } else {
      int a = st.top();
      st.pop();
      int b = st.top();
      st.pop();
      if (S[i] == '+'){
        st.push(a | b);
      }
      if (S[i] == '*'){
        st.push(a & b);
      }
      if (S[i] == '^'){
        st.push(a ^ b);
      }
    }
  }
  return st.top();
}
int main(){
  while (1){
    string S;
    cin >> S;
    if (S == "."){
      break;
    }
    string P;
    cin >> P;
    reverse(S.begin(), S.end());
    int N = S.size();
    string T;
    for (int i = 0; i < N; i++){
      if (S[i] != '[' && S[i] != ']'){
        T += S[i];
      }
    }
    int ans1 = eval(T, P);
    int ans2 = 0;
    for (int i = 0; i < 10000; i++){
      if (eval(T, to_string(i)) == ans1){
        ans2++;
      }
    }
    cout << ans1 << ' ' << ans2 << endl;
  }
}


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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

int n, m;
vector<ll> node(100001, 0);
vector<vector<edge>> side(100001);
vector<bool> isVisited(100001, false);

void dfs(int parent, ll cost){
    isVisited[parent] = true;
    for(auto &n: side[parent]){
        if(isVisited[n.to]) continue;
        node[n.to] = cost + n.cost;
        dfs(n.to, cost+n.cost);
    }
}

void solve()
{
    cin >> n >> m;
    int l[m], r[m];
    ll d[m];
    REP(i, m) {
        int _l, _r;
        cin >> _l >> _r;
        ll _d;
        cin >> _d;
        edge le = {_r, _d};
        edge re = {_l, -_d};
        side[_l].push_back(le);
        side[_r].push_back(re);
        l[i] = _l;
        r[i] = _r;
        d[i] = _d;
    }
    for(int i = 1; i <= n; i++){
        if(!isVisited[i]) dfs(i, 0);
    }
    REP(i, m){
        if(node[r[i]] - node[l[i]] != d[i]) {
            cout << "No" << "\n";
            return;
        } 
    }
    cout << "Yes" << "\n";
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int L;

	cin >> N >> L;
	vector<string> S(N);

	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}
	
	sort(S.begin(), S.end());  // 昇順にソート

	for (int i = 0; i < N; i++) {
		cout << S.at(i);
	}
	
	return 0;
}

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

void erase(int i, std::vector<int>& v)
{
  auto it = std::find(v.begin(), v.end(), i);
  v.erase(it);
}

int solve(int a, int b)
{
  std::vector<int> v = {1, 2, 3};
  erase(a, v);
  erase(b, v);
  return v.front();
}

int main()
{
  int a, b;
  std::cin >> a >> b;

  std::cout << solve(a, b) << std::endl;
}


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

int main()
{
    int n,i;
    string s;
    cin>>n>>s;
    if(n&1) cout<<"No";
    else
    {int a=0;
       for(i=0;i<n/2;i++)
       {
           if(s[i]!=s[n/2+i]){a=1;break;}
       }
       if(a) cout<<"No";
       else cout<<"Yes";
    }cout<<endl;
    return 0;
}


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

int main()
{
	int x, a, b;
	cin >> x >> a >> b;

	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}

	

}





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

namespace AtCoder0627
{
	class Program
	{
		static void Main(string[] args)
		{
			A();
		}

		private static void B()
		{
			var cases = int.Parse(Console.ReadLine());
			var sols = new List<int>();
			for (int i = 0; i < cases; i++)
			{
				var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
				var a = ints[0];
				var b = ints[1];
				var n = ints[2];

				//sols.Add();
			}

			sols.ForEach(x => Console.WriteLine(x));
		}

		private static void A()
		{
			var a = int.Parse(Console.ReadLine());
			Console.WriteLine(a + a * a + a * a * a);
		}
	}
}


Measured memory_bytes: 27532
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 2e5 + 5;

int n, k;
int arr[N];

int main()
{
  cin >> k >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> arr[i];
  int best = arr[n - 1] - arr[0];
  for(int i = 0 ; i < n - 1; i++) {
    best = min(best, arr[i] + k - arr[i + 1]);
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cctype>

using namespace std;

long long int gcd(long long int a, long long int b){
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	else 
	return gcd(b, a%b);
}

long long int lcm(long long int c, long long int d){
	return c*d / gcd(c, d);
}

int main(){
	long long int M, N;
	while (cin>>M>>N){
		cout << gcd(M, N) << " " << lcm(M, N) << "\n";
	}
	return 0;
}

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

int main() {
  int H, W;
  
  cin >> H >> W;
  
  string board[50];
  
  for (int i = 0; i < H; i++) cin >> board[i];
  
  // チェックする8方向のマス目の座標
  // 基準とするマスからどこにあるか
  // dx[0] = x座標
  // dy[0] = y座標
  // dx[0], dy[0]と対応している
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      // 地雷のマス目だったらこの後の検査をしない
      if (board[i][j] == '#') continue;
      
      // 現在のマスから8方向検査
      int total = 0;
      for (int d = 0; d < 8; d++) {
        const int nextI = dy[d] + i;
        const int nextJ = dx[d] + j;
        
        // マス目の外は検査しない
        // if (nextJ >= 0 && W >= nextJ &&
        //     nextI >= 0 && H >= nextI &&
        //     board[nextI][nextJ] == '#')
        //   total++;
        
        // 以下は模範解答にあった書き方
        if(nextI < 0 || H <= nextI) continue;
        if(nextJ < 0 || W <= nextJ) continue;
        if (board[nextI][nextJ] == '#') total++;
      }
      
      board[i][j] = '0' + total;
    }
  }
  
  for (int i = 0; i < H; i++) cout << board[i] << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

pub fn lower_bound<T: Ord>(a: &Vec<T>, x: &T) -> usize {
    use std::cmp::Ordering;
    let mut l = 0;
    let mut r = a.len();
    while l != r {
        let m = l + (r - l) / 2;
        match a[m].cmp(x) {
            Ordering::Less => l = m + 1,
            Ordering::Equal | Ordering::Greater => r = m,
        }
    }
    l
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      aa: [u64; n],
    }

    use std::collections::VecDeque;
    let mut q = vec![];
    for a in aa {
        let idx = lower_bound(&q, &a);
        if idx > 0 {
            q[idx-1] = a;
        } else if idx == 0 {
            q.insert(0, a);
        }
        debug!(q);
    }
    puts!("{}\n", q.len());
}


Measured memory_bytes: 6396
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

int main(void) {
    int n, x, d=0, l, i, ans=1;
    cin >> n >> x;
    for (i = 1; i <= n; i++) {
        cin >> l;
        d += l;
        if (d <= x) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if(W >= x + r && x >= r && H >= y + r && y >= r){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3112
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int sum = 0;
    for(int i=1;i<=N;i++){
      if(sumDigits(i)<=B && sumDigits(i) >= A){
        sum += i;
      }
    }
    System.out.println(sum);
  }

  public static int sumDigits(int n){
    int sum = 0;
    while(n > 0){
      sum += n%10;
      n /= 10;
    }
    return sum;
  }

}


Measured memory_bytes: 23124