akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;				//長方形の中の円

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();

		if(x >= r && x <= W-r && y >= r && y <= H-r){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26316
import fractions
  
def lcm(a,b):
  return (a * b) // fractions.gcd(a, b)

N,M = map(int,input().split())
S = input()
T = input()

if M > N:
  N,M = M,N
  S,T = T,S

X = lcm(N,M)

n = N // fractions.gcd(N,M)
m = M // fractions.gcd(N,M)

for i in range(0,X,m):
  if S[0] != T[0]:
    print(-1)
    break
  elif i % n == 0:
    s = i // n
    t = i // m
    if S[t] != T[s]:
      print(-1)
      break
else:
  print(X)


Measured memory_bytes: 5428
#include <stdio.h>

int mmap[2010][2010],ll[2010][2010],rr[2010][2010],uu[2010][2010],dd[2010][2010];

int main()
{

    int h,w;
    scanf("%d%d",&h,&w);
    for (int i=1;i<=h;i++)
    for (int j=1;j<=w;j++)
    {
        char ch=getchar();
        while (ch!='.' && ch!='#') ch=getchar();
        if (ch=='.') mmap[i][j]=1;
        else mmap[i][j]=0;
    }
    for (int i=1;i<=h;i++)
        ll[i][0]=ll[i][w+1]=rr[i][0]=rr[i][w+1]=0;
    for (int j=1;j<=w;j++)
        uu[0][j]=uu[h+1][j]=dd[0][j]=dd[h+1][j]=0;
    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            if (mmap[i][j]) ll[i][j]=ll[i][j-1]+1;
            else ll[i][j]=0;
        }
        for (int j=w;j>=1;j--)
        {
            if (mmap[i][j]) rr[i][j]=rr[i][j+1]+1;
            else rr[i][j]=0;
        }
    }
    for (int j=1;j<=w;j++)
    {
        for (int i=1;i<=h;i++)
            if (mmap[i][j]) uu[i][j]=uu[i-1][j]+1;
            else uu[i][j]=0;
        for (int i=h;i>=1;i--)
            if (mmap[i][j]) dd[i][j]=dd[i+1][j]+1;
            else dd[i][j]=0;
    }
    int ans=0;
    for (int i=1;i<=h;i++)
    for (int j=1;j<=w;j++)
    {
        if (mmap[i][j])
        {
            int tmp=uu[i][j]+dd[i][j]+ll[i][j]+rr[i][j]-3;
            if (tmp>ans) ans=tmp;
        }
    }

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


Measured memory_bytes: 78976
n = int(input())
build, floors, rooms = (4, 3, 10)

buildings = [[[0 for i in range(rooms)] for j in range(floors)] for k in range(build)]


for k in range(n):
    b, f, r, v = map(int, input().split())
    buildings[b-1][f-1][r-1] = buildings[b-1][f-1][r-1] + v

for i in range(4):

    for o in buildings[i]:
        print("", *o, sep=" ")

    if i < 3:
        print("#" * 20)



Measured memory_bytes: 5624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	cout << 10 - N / 200 << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,a,i;
	cin>>n;
	a=7;
	for(i=1;i<=n;i++){
		a=a%n; 
		if(a==0){
			cout<<i;
			return 0;
		}
		a=a*10+7;
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX_N = 100;
typedef long long lint;

int main() {
	int r,c;
	int a[MAX_N+1][MAX_N+1]={0};
	int sum=0;
	//in
	cin>>r>>c;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
		}
	}
	//summer
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			a[i][c]+=a[i][j];
			a[r][j]+=a[i][j];
			sum+=a[i][j];
		}
	}
	a[r][c]=sum;
	//out
	for(int i=0;i<r+1;i++){
		for(int j=0;j<c+1;j++){
			if((j==c)){
				cout<<a[i][j];
			}else{cout<<a[i][j]<<" ";}
		}
		cout<<endl;
	}
	
	
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
str s,t;
int ans;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>t;
    for(int i=0;i<s.size();i++)if(s[i]==t[i])ans++;
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
const lli MOD = 1000000007;
int a[100005];
vector<int> e[100005];
lli route[100005];
int start = 0;
void bye(vector<int> ans)

{
    cout << ans.size() << endl;
    for (auto to : ans)
        cout << to + 1 << " ";
    exit(0);
}
bool dfs(int cur, int prev)
{
    route[cur] = prev;

    bool flag = false;
    for (auto to : e[cur]) {
        if (route[to] == -1) {
            flag = true;
            dfs(to, cur);
        }
    }
    if (!flag) {
        bool fl = true;
        for (auto to : e[start]) {
            if (route[to] == -1) {
                fl = false;
                break;
            }
        }
        if (fl) {
            vector<int> ans;
            while (cur != -2) {
                ans.push_back(cur);
                cur = route[cur];
            }
            bye(ans);
        }
    }


    route[cur] = -1;
}
int main()
{
    int n, m;
    cin >> n >> m;
    int a, b;
    rep(i, m)
    {
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    vector<int> one;
    vector<pair<int, int>> hoge;
    rep(i, n)
    {
        if (e[i].size() == 1)
            one.push_back(i);
        hoge.push_back(make_pair(e[i].size(), i));
    }
    sort(hoge.begin(), hoge.end());
    rep(i, n) route[i] = -1;
    vector<int> ans;
    rep(i, n)
    {
        rep(j, n) route[j] = -1;
        start = hoge[i].second;
        queue<int> que;
        dfs(start, -2);
    }
}


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

int main(void){

    int N, X, Y; cin>>N>>X>>Y;
    vector<int> ans(4*1000000+2,0);
    for (int i = 1; i <= N-1; ++i) {
        for (int j = i+1; j <= N; ++j) {
            int dis1 = abs(i-j);
            int dis2 = abs(X-i)+abs(Y-j)+1;
            int dis3 = abs(X-j)+abs(Y-i)+1;
            ans[min({dis1,dis2,dis3})]++;
        }
    }

    for (int i = 1; i < N; ++i) {
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
   cout << fixed << setprecision(10);
   string input;
   cin >> input;
   if (input == "Sunny") cout << "Cloudy" << endl;
   else if (input == "Cloudy") cout << "Rainy" << endl;
   else cout << "Sunny" << endl;
   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
constexpr int MAX = 10000;
bool fld[MAX][MAX];
int memo[MAX];
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int W, H, K, N;
    std::cin >> W >> H >> K >> N;
    for (int i = 0, y, x; i < N; i++) { std::cin >> x >> y, fld[y - 1][x - 1] = 1; }
    const int WNUM = (W + 1) / 2;
    K -= WNUM;
    if (K < 0) { return std::cout << -1 << std::endl, 0; }
    auto ok = [&](const int y, const int x) { return fld[y][x] == 0; };
    int two = 0, ans = 0;
    for (int y = 2; y < H; y += 2) {
        std::fill(memo, memo + MAX, -1);
        auto rec = [&](auto&& self, const int x) {
            if (x == -2) { return 0; }
            if (memo[x] != -1) { return memo[x]; }
            if (x == 0) { return memo[x] = (ok(y - 1, x) ? 1 : 2); }
            return memo[x] = std::min((ok(y - 1, x - 1) ? 2 : 4) + self(self, x - 4), (ok(y - 1, x) ? 1 : 2) + self(self, x - 2));
        };
        const int score = rec(rec, W - 1);
        ans += score, two += score - WNUM;
    }
    const int t = std::min(K, two);
    ans -= 2 * t, K -= t, ans -= K;
    std::cout << std::max(0, ans) << std::endl;
    return 0;
}



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


int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    bool flag = false;

    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag = true;
            break;
        }
    }

    if(flag)
    {
        cout<<"OK"<<endl;
    }
    else
    {
        cout<<"NG"<<endl;
    }
    
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

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

    unordered_map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        ++mp[A[i]];
    }

    ll sum = 0;
    for (const auto& p : mp) {
        sum += p.second * (p.second - 1) / 2;
    }

    for (int k = 0; k < N; k++) {
        ll ans = sum;
        ll num = mp[A[k]];
        ans -= num * (num - 1) / 2;
        ans += (num - 1) * (num - 2) / 2;
        cout << ans << '\n';
    }

    return 0;
}


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

using namespace std;

int a, b;
int product = 1;



int main () {

    cin >> a >> b;
    if (a > 0 && b > 0){
        cout << "Positive" << "\n";
    }
    if (a <= 0 && b >= 0){
        cout << "Zero" << "\n";
    }
    if (a < 0 && b < 0){
        if ((b - a + 1)%2 == 0){
            cout << "Positive" << "\n";
        }
        else {
            cout << "Negative" << "\n";
        }
    }

    return 0;

}

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

using namespace std;
using ll = long long;

// inf
const ll infl = 1LL << 60;
const int inf = 1 << 30;

int main() {
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    
    int ans = 0;
    while (*max_element(H.begin(), H.end()) > 0) {
        for (int i = 0; i < N; ++i) {
            if (H[i] > 0) {
                int pc = H[i];
                int j;
                for (j = i; j < N; ++j) {
                    if (H[j] == 0) break;
                    
                    pc = min(pc, H[j]);
                }
                ans += pc;
                for (int k = i; k < j; ++k) {
                    H[k] -= pc;
                }

                i = j;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

long long n, dp[110][100100], weight[110], val[110], w;

long long solve(int pos, int curr) {
	if(pos == n) return 0;
	long long &ret = dp[pos][curr];
	if(ret != -1) return ret;
	ret = solve(pos+1, curr);
	if(curr >= weight[pos]) ret = max(ret, solve(pos+1, curr-weight[pos]) + val[pos]);
	return ret;
}

int main() {
	cin>>n>>w;
	for(int i = 0; i < n; i++) {
		cin>>weight[i]>>val[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(0, w)<<endl;
	return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int a[n];
	FOR(i,0,n)cin >> a[i];
	int ans = 0;
	while(true){
	    bool odd = false;
	    FOR(i,0,n){
	        if(a[i] % 2 == 1){
	            odd = true;
	            break;
	        }else{
	            a[i] = a[i] / 2;
	        }
	    }
	    if(odd)break;
	    ans++;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c;
    bool flag = 0;
    cin >> a >> b >> c;

    if((a<c&&c<b)||b<c&&c<a){
        flag = 1;
    }

    if (flag == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

int a, b, c;

int main()
{
    int rez = 0;

    cin >> a >> b >> c;
    if(a + b >= c - 1)
        rez = b + c;

    else
        rez = a + b + 1 + b;

    cout << rez << "\n";

    return 0;
}


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

h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]

reverse = 0
count = 0
print_list = []
for h_ in range(h):
    iter_ = range(w)
    if reverse == 1:
        iter_ = reversed(iter_)
    for w_ in iter_:
        if a[h_][w_] % 2 != 0:
            a[h_][w_] -= 1
            if reverse == 0 and w_ == (w-1):
                ww, hh = w_, h_+1
            elif reverse == 1 and w_ == 0:
                ww, hh = w_, h_+1
            else:
                ww, hh = w_+1, h_

            if hh == h:
                continue
            count += 1
            a[hh][ww] += 1

            print_list.append([h_+1, w_+1, hh+1, ww+1])

print(count)
for i in print_list:
    print(*i)


Measured memory_bytes: 32500
#include <iostream>
using namespace std;
int main()
{
	int n,a;
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		for( ; ; )
		{
		if(a%2==0)
		{
			ans++;
			a/=2;
		}
		else
		break;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int h,m,a,b,k;
  cin>>h>>m>>a>>b>>k;
  long long int up=h*60+m;
  long long int donw=a*60+b;
  long long int ans=donw-up-k;
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    Cout(a<=c && c<=b ? "Yes" : "No");
}

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

int main() {

	int n, m;
	cin >> n >> m;
	
	vector<pair<long long, long long> > vc;
	for (int i=0; i<n; i++) {
		long long a, b;
		cin >> a >> b;
		vc.push_back(make_pair(a,b));
	}
	sort(vc.begin(), vc.end());
	
	long long need = m;
	long long ind = 0;
	long long cost = 0;
	
	while (need > 0 && ind != n) {
		long long get = min(need, vc[ind].second);
		vc[ind].second -= get;
		need -= get;
		cost += get * vc[ind].first;
		ind++;
	}
	
	cout << cost << endl;
	
}


Measured memory_bytes: 2420
var input= require("fs").readFileSync("/dev/stdin", "utf8");
input=input.split(" ");
var a=parseInt(input[0]);
var b=parseInt(input[1]);
if(a == b){
    console.log("a == b");
}
else if(a>b){
    console.log("a > b");
}
else{
    console.log("a < b");
}


Measured memory_bytes: 15092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

int main(){

    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(j, N) cin >> Q[j];

    vector<int> R = P;
    sort(R.begin(), R.end());

    int count_P, count_Q = 0;
    int k = 0;
    do{
        if (R==P) count_P = k;
        if (R==Q) count_Q = k;
        k++;
    }
    while(next_permutation(R.begin(), R.end()));
    
    int ans = 0;
    ans = abs(count_P-count_Q);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;


int main() {
  int N,K;cin >>N >> K;
  vll a(N);
  vll sum(N+1,0);
  vll sump(N+1,0);
  repeat(i,N){
    cin >> a[i];
    sum[i+1] += sum[i]+a[i];
    sump[i+1] += sump[i];
    if(a[i] > 0) sump[i+1] += a[i];
  }
  ll ans = 0;
  repeat(i,N-K+1){
    ll aa = sump[i]+sump[N]-sump[i+K];
    if(sum[i+K]-sum[i]>0)
      aa += sum[i+K]-sum[i];
    ans = max(ans,aa);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
	"sort"
)

type Ball struct {
	Num int
	Cnt int
}
type Balls []Ball

func (b Balls) Len() int           { return len(b) }
func (b Balls) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
func (b Balls) Less(i, j int) bool { return b[i].Cnt < b[j].Cnt }

func main() {
	var N, K, a, r int
	fmt.Scan(&N, &K)
	m := map[int]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&a)
		m[a]++
	}
	var ba Balls
	for k, v := range m {
		ba = append(ba, Ball{Num: k, Cnt: v})
	}
	sort.Sort(Balls(ba))
	for i := 0; i < len(ba)-K; i++ {

		r += ba[i].Cnt
	}
	fmt.Println(r)
}

Measured memory_bytes: 20864
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<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 INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];

    vector<int> a(n), b(n);
    REP(i, n) a[i] = i+1;
    REP(i, n) b[i] = 1e9 - i;
    REP(i, n) a[p[i]-1] += i;

    int num = 0;
    FOR(i, 1, n)
    {
        num = max(num+1, max(0, a[i-1] - a[i] + 1));
        a[i] += num;
        b[i] -= num;
    }
    REP(i, n) cout << a[i] << " \n"[i == n-1];
    REP(i, n) cout << b[i] << " \n"[i == n-1];

}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int n,W,v[110],w[110];long long f[100010]={0};
int main(){
	scanf("%d %d",&n,&W);
	for(int i=1;i<=n;i++) scanf("%d %d",&w[i],&v[i]);
	for(int i=1;i<=n;i++){
		for(int j=W;j>=w[i];j--){
			f[j]=max(f[j],f[j-w[i]]+v[i]);
		}
	}
	cout<<f[W];
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int A[] =new int[N+1];
    int B[] =new int[N+1];
    int C[] =new int[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();}
    A[N]=0;
    B[0]=0;
    for(int j=1;j<N+1;j++){
      B[j]=B[j-1]+sc.nextInt();}
    int x=B[N];
    if(N==1){System.out.println(x);}
    for(int k=0;k<N-1;k++){
      C[k]=sc.nextInt();}
      for(int l=0;l<N;l++){
        if(A[l+1]==A[l]+1){x=x+C[A[l]-1];}}
    System.out.println(x);
  }
}

Measured memory_bytes: 23124
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

void Div(int dividend, int divisor, int a[])
{
    for (int i = 0; i < divisor; ++i)
    {
        a[i] = dividend / divisor + ((dividend % divisor > i) ? 1 : 0);
    }
}

int main()
{
    int N;
    cin >> N;
    int s[N];
    REP(i, N) cin >> s[i];
    sort(s, s + N);
    int sum = 0;
    REP(i, N) sum += s[i];
    if (sum % 10 != 0)
    {
        cout << sum << endl;
    }
    else
    {
        REP(i, N)
        {
            if (s[i] % 10 != 0)
            {
                cout << sum - s[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='C')
        cout<<'G'<<endl;
    else if(s[0]=='G')
        cout<<'C'<<endl;
    else if(s[0]=='A')
        cout<<'T'<<endl;
    else cout<<'A'<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 2000000000
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
bool chk(int x){
	int pos[10],neg[10],nX=x,id=0;
	while(x/10){
		pos[id++]=x%10;
		x/=10;
	}
	pos[id++]=x%10;
	id=0;
	while(nX/10){
		neg[id++]=nX%10;
		nX/=10;
	}
	neg[id++]=x%10;
	for(int i=0,j=id-1;i<id&&j>=0;i++,j--) if(pos[i]!=neg[j]) return 0;
	return 1;
}
int main(){
	int a,b;
	while(~getII(a,b)){
		int ans=0;
		for(int i=a;i<=b;i++) if(chk(i)) ans++;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  int sum = 1, bad = 1;
  rep(i, N)
  {
    cin >> A[i];
    sum *= 3;
    if (A[i] % 2 == 0){  // A[i]偶数のとき、B[i]は奇数（A[i]-1,a[i]+1）
      bad *= 2;
    }
  }
  printf("%d\n", sum - bad);

  return 0;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


string s,t;

void solve(){
  cin >> s >> t;
  char x=t[s.size()];
  if(s+x==t)cout << "Yes";
  else cout << "No";
  cout << endl;
}

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    int N; cin>>N;
    int ans=0;
    vector<int> s(N,0);
    int mini=100;
    for(int i=0;i<N;i++){
        cin>>s[i];
        ans+=s[i];
        if(s[i]%10!=0){
            mini=min(mini,s[i]);
        }
    }
    if(ans%10==0){
        ans-=mini;
        if(mini==100)ans=0;
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

#define mod 1000000007

int main(){
	string s,t;
	cin >> s;
	cin >> t;
	vector<int> sa,sb,ta,tb;
	sa.push_back(0);
	for(int i = 0;i < s.length();i++){
		sa.push_back(sa[i]);
		if(s[i] == 'A') sa[i+1] += 1;
		else sa[i+1] += 2;
	}
	ta.push_back(0);
	for(int i = 0;i < t.length();i++){
		ta.push_back(ta[i]);
		if(t[i] == 'A') ta[i+1] += 1;
		else ta[i+1] += 2;
	}
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		int csa,csb,cta,ctb;
		if((sa[b]-sa[a-1])%3 == (ta[d]-ta[c-1])%3){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
}


Measured memory_bytes: 1788
/*
 * AtCode Beginner Contest 138 : B.Resistor in Parallel
 * Author : anaksoleh
 * 18 August 2019
 *
 */



#include <bits/stdc++.h>
using namespace std;

int N;
float x = (1/10e4);

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

	double A,B;
	
	cin>>N;

	if(N >= 2){
		cin>>A>>B;
		double pembilang = A + B,pembagi = A*B;
		N-=2;
		while(N--)
		{
			cin>>A;
			pembilang = (A*pembilang) + pembagi;
			pembagi = A*pembagi;
		}

		cout << pembagi/pembilang << '\n';

	}else{
		cin>>A;
		cout << A << '\n';
	}

	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout << (int)st.size() << endl;
}


Measured memory_bytes: 256
h,w=[int(i) for i in input().split()]
s=[input() for _ in range(h)]
	
#upper upperleft left lowerleft lower lowerright right upperright  
move=[[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1]]

for y in range(h):
	for x in range(w):
		cnt=0
		if s[y][x]=='#':continue
		
		for i in range(8):
			yi=y+move[i][0]
			xi=x+move[i][1]
			if 0<=xi<w and 0<=yi<h:
				if s[yi][xi]=='#':cnt+=1
			else:continue
		sl=list(s[y])
		sl[x]=str(cnt)
		s[y]=''.join(sl)
print("\n".join(s))

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int i,a,b,c;
    int s[3]={1,2,3};
    scanf("%d",&a);
    scanf("%d",&b);
    for(i=0;i<3;i++)
    {
        if(a==s[i] || b==s[i])
            s[i]=0;
    }
    for(i=0;i<3;i++)
    {
        if(s[i]!=0)
            printf("%d\n",s[i]);
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            int ans = 0;
            for(int i = a; i <= b; i++)
            {
                if (i % 10 == i / 10000 && (i % 100) / 10 == (i / 1000) % 10)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <map>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX 1000003
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(ll mod)
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
    int q;
    cin >> q;
    COMinit(MAX);
    for (int i = 0; i < q; i++)
    {
        ll x, d, n;
        cin >> x >> d >> n;
        ll init = x * inv[d];
        init %= MAX;
        if(d==0){
            cout<<modpow(x,n,MAX)<<endl;
            continue;
        }
        if (init + n - 1 >= MAX||init==0)
        {
            cout << 0 << endl;
        }
        else
        {
            ll tmp = fac[init + n - 1] * finv[init - 1];
            tmp %= MAX;
            tmp *= modpow(d, n, MAX);
            tmp %= MAX;
            cout << tmp << endl;
        }
    }
}


Measured memory_bytes: 24320
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=201000;
int n,a[N],cnt[N];
bool check() {
	int m=a[n-1];
	if (m==1) {
		if (cnt[m]!=2) return 0;
	}
	rep(i,1,m+1) {
		if (2*i<m) { if (cnt[i]!=0) return 0; }
		if (2*i==m) { if (cnt[i]!=1) return 0; }
		if (2*i==m+1) { if (cnt[i]!=2) return 0; }
		if (2*i>m) { if (cnt[i]<=1) return 0; }
	}
	return 1;
}
int main() {
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i),cnt[a[i]]++;
	sort(a,a+n);
	puts(check()?"Possible":"Impossible");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
int n;
double a[222],b[222],d[222];
 
double calc(int i,double m) {
  double t=d[i-1],ans=0;
  ans+=t*m+m*m/2;
  t+=m;
  if(t>b[i]) ans-=(t-b[i])*(t-b[i]);
  t-=a[i]-m;
  d[i]=t;
  ans+=t*(a[i]-m)+(a[i]-m)*(a[i]-m)/2;
  double sum=0;
  REP(j,i+1,n) {
    if(t-sum>b[j]) return -MAX;
    sum+=a[j];
  }
  return ans;
}
void Main() {
  R n;
  REP(i,1,n+1) R a[i];
  REP(i,1,n+1) R b[i];
  n+=2;
  a[0]=a[n-1]=b[0]=b[n-1]=0;
  double ans=0;
  mem(d);
  REP(i,1,n-1) {
    double l=0,r=a[i];
    rep(tt,300) {
      double m1=(l*2+r)/3,m2=(l+r*2)/3;
      double d1=calc(i,m1),d2=calc(i,m2);
      if(d1>=d2) r=m2;
      else l=m1;
    }
    ans+=calc(i,l);
  }
  printf("%.10f",ans);
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n,a,b;cin>>n>>a>>b;
    if(a>b)cout<<0;
    else if(a<b&&n==1)cout<<0;
    else if(n==1)cout<<1;
    else cout<<(n-2)*(b-a)+1;
    
    return 0;
}

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

int main() {
    string abcd;
    cin >> abcd;
    for (int bit = 0; bit < 0b1000; ++bit){
        int s = (int)(abcd[0] - '0');
        rep(i, 3){
            if(bit & (1 << i)) {
                s += (int)(abcd[i+1] - '0');
            } else {
                s -= (int)(abcd[i+1] - '0');
            }
        }
        if(s == 7){
            cout << abcd[0];
            rep(i, 3) {
                if(bit & (1 << (i))){
                    cout << "+";
                } else {
                    cout << "-";
                }
                cout << abcd[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<cctype>
#include <algorithm>
#include<string>
 
using namespace std;
 
int main(){
    int cnt = 0,a = 0,b = 0;
    string str, cmd , p;
     
    cin >> str;
    cin >> cnt;
     
    for(int x = 0; x < cnt; x++){
        cin >> cmd >> a >> b;
     
        if (cmd == "print"){
            cout << str.substr(a,b-a+1) << endl;
        }
        else if (cmd == "reverse"){
            reverse(str.begin()+a,str.begin()+b+1);
        }
        else if (cmd == "replace"){
            cin >> p;
            str.replace(a,p.length(),p);
        }
    }
     
    return 0;
}

Measured memory_bytes: 1220
import static java.util.Arrays.sort;
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] ary = new long[n];
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextLong();
        }
        sort(ary);
        long tmp = 1;
        for(int i = 0;i < n;i++){
            tmp = lcm(tmp,ary[i]);
        }
        System.out.print(tmp);
    }
    static long gcd(long a,long b){
    long candidate = a;
    while (b % a != 0) {
      candidate = b % a;
      b = a;
      a = candidate;
    }
    return candidate;
  }
    
    static long lcm(long a,long b){
        return a/gcd(a,b) * b;
    }
}



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


int main() {
  int n;
  cin >> n;
  if(n==2){
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
  else{
    cout<<"Hello World"<<endl;
  }
  
}




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

int main() {
    int k,n;
    cin >> k >> n;
    vector<int> v(n);
    rep(i,n) cin >> v.at(i);
    vector<int> dif(n);
    rep(i,n-1) dif.at(i) = v.at(i+1) - v.at(i);
    dif.at(n-1) = k + v.at(0) - v.at(n-1);

    int max = *max_element(dif.begin(), dif.end());
    int ans = k - max;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define N 100005
#define inf 2000000000000000ll
using namespace std;
struct node {
    long long x,y;
}a[N];
vector<node>G[N];
long long i,j,k,l,s,n,m,vis[N],x,y,z,q[N];
inline void build(long long x) {
    vis[x]=1;
    long long l=0,r=1; q[1]=x;
    a[x].x=1,a[x].y=0;
    while (l<r) {
        long long k=q[++l];
        for (long long i=0;i<G[k].size();i++) {
            if (vis[G[k][i].x]) continue;
            vis[G[k][i].x]=1;
            a[G[k][i].x].x=-a[k].x;
            a[G[k][i].x].y=G[k][i].y-a[k].y;
            q[++r]=G[k][i].x;
        }
    }
}
int main() {
    scanf("%lld%lld",&n,&m);
    for (i=1;i<=m;i++) scanf("%lld%lld%lld",&x,&y,&z),G[x].pb(node{y,z}),G[y].pb(node{x,z});
    build(1);
    long long bb=0;
    for (i=1;i<=n;i++)
    for (j=0;j<G[i].size();j++) {
        if (a[i].x+a[G[i][j].x].x) {
            long long gt=G[i][j].y-a[i].y-a[G[i][j].x].y;
            if (a[i].x<0) gt=-gt;
            if (gt&1) return puts("0"),0;
            if (!bb) bb=gt/2;
            if (bb!=gt/2) return puts("0"),0;
        }
        else {
            if (a[i].y+a[G[i][j].x].y!=G[i][j].y) return puts("0"),0;
        }
    }
    long long L=-inf,R=inf;
    for (i=1;i<=n;i++) {
        if (a[i].x==1) L=max(L,-a[i].y);
        if (a[i].x==-1) R=min(R,a[i].y);
    }
    L++,R--;
    if (bb) {
        if (bb>=L&&bb<=R) return puts("1"),0;
        return puts("0"),0;
    }
    else printf("%lld\n",max(0ll,R-L+1));
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n%2==1) cout<<0<<endl;
  else{
    n/=2;
    int ans=0;
    int now=5;
    while(n/now){
      ans+=(n/now);
      now*=5;
    }
    
    cout<<ans<<endl;
  }
   


  return 0;
}


Measured memory_bytes: 3636
use proconio::input;

fn main() {
    input! {
        n: usize,
        aa: [isize; n],
        bb: [isize; n],
    }

    let mut positives = vec![];
    let mut negatives = vec![];

    for (a, b) in aa.into_iter().zip(bb.into_iter()) {
        let diff = a - b;
        if diff >= 0 {
            positives.push(diff);
        } else {
            negatives.push(diff);
        }
    }

    if negatives.len() == 0 {
        println!("0");
        return;
    }

    let mut count = negatives.len();

    let negative_sum = negatives.into_iter().sum::<isize>();
    let mut positive_sum = 0;

    positives.sort();
    positives.reverse();

    for positive in positives {
        positive_sum += positive;
        count += 1;

        if positive_sum + negative_sum >= 0 {
            println!("{}", count);
            return;
        }
    }

    println!("-1");
}


Measured memory_bytes: 6272
def solve():
    N = int(input())
    red = [list(map(int, input().split())) for _ in range(N)]
    blue = [list(map(int, input().split())) for _ in range(N)]
    blue.sort()
    red.sort(key=lambda x:-x[1])
    pairs = [False]*N
    for bx,by in blue:
        for i, (ax,ay) in enumerate(red):
            if pairs[i]==False and ay<by and ax<bx:
                pairs[i] = True
                break
    ans = pairs.count(True)
    return ans
print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long int ll;
const int N=1e5+5;
int n,W,w[N],v[N],ans;
ll dp[105][N];
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n>>W;
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    if(w[0]<=W){
        dp[0][v[0]]=w[0];
        ans=v[0];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<N;j++){
            if( (dp[i-1][j]||!j) &&dp[i-1][j]+w[i]<=W){
                dp[i][j+v[i]]=(dp[i][j+v[i]]?min(dp[i-1][j]+w[i],dp[i][j+v[i]]):dp[i-1][j]+w[i]);
                ans=max(ans,j+v[i]);
            }
            if(!dp[i][j]) dp[i][j]=max(dp[i][j],dp[i-1][j]);
            else
            if(dp[i-1][j])
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 79360
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int H, W, K;

int w[1010];
int S[1010][11];

signed main()
{
	cin >> H >> W >> K;
	REP(i, H)
	{
		char str[1010];
		cin >> str;
		REP(j, W)
		{
			S[j][i] = str[j] - '0';
		}
	}

	int min_cut = INT_MAX;

	int bit_end = pow(2, (H - 1));
	int sec[11];
	for (int bit = 0; bit < bit_end; bit++)
	{
		int cut = 0;
		int sec_cnt = 0;
		for (int h = 0; h < H; h++)
		{
			sec[h] = sec_cnt;
			if ((bit >> h) & 1)
			{
				sec_cnt++;
			}
		}
		cut += sec_cnt;
		sec_cnt++;

		int w_cnt[11] = {};
		for (int x = 0; x < W; x++)
		{
			int cur_w_cnt[11] = {};
			for (int y = 0; y < H; y++)
			{
				if (S[x][y] == 1)
				{
					cur_w_cnt[sec[y]]++;
				}
			}

			bool is_end = false;
			bool need_cut = false;
			for (int s = 0; s < sec_cnt; s++)
			{
				if (w_cnt[s] + cur_w_cnt[s] > K)
				{
					need_cut = true;
				}
				if (cur_w_cnt[s] > K)
				{
					is_end = true;
				}
			}

			if (is_end) goto END;

			if (need_cut)
			{
				cut++;
				for (int s = 0; s < sec_cnt; s++)
				{
					w_cnt[s] = cur_w_cnt[s];
				}
			}
			else
			{
				for (int s = 0; s < sec_cnt; s++)
				{
					w_cnt[s] += cur_w_cnt[s];
				}
			}
		}

		min_cut = min(cut, min_cut);

	END:;
	}

	cout << min_cut << endl;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N; cin >> N;
    map<int,int> m{};
    for(int i=0;i<N;i++){int n; cin >> n; m[n]++;}
    int M; cin >> M;
    for(int i=0;i<M;i++){int n; cin >> n; m[n]--;}
    string ans="YES";
    for(auto i=m.begin(); i!=m.end();i++){
        int n = i->second;
        if(n<0) {ans="NO"; break;}
    }
    cout << ans << endl;
}


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

int main()
{
        long long a, b;

        cin >> a >> b;

        long long num = 0;
        for (int i = 0; i < b; ++i) {

                num = a * (i + 1);
                if (num % b == 0) {
                        break;
                }
        }
        cout << num << endl;

}


Measured memory_bytes: 256