akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  string str;
  cin>>str;
  if(str.at(0)=='S'){cout<<"Cloudy"<<endl;}
  if(str.at(0)=='C'){cout<<"Rainy"<<endl;}
  if(str.at(0)=='R'){cout<<"Sunny"<<endl;}
}

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

using Int = long long;
using ll = long long;

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

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

  Int n,m;
  while(cin>>n>>m,n||m){
    vector<Int> as(n),ws(m);
    for(Int i=0;i<n;i++) cin>>as[i];
    for(Int i=0;i<m;i++) cin>>ws[i];

    Int s=1<<m;
    vector<Int> sm(s,0);
    for(Int b=0;b<s;b++)
      for(Int i=0;i<m;i++)
        if((b>>i)&1) sm[b]+=ws[i];

    vector<Int> ts;
    ts.emplace_back(0);
    for(Int b=0;b<s;b++){
      for(Int c=0;c<s;c++){
        if(b&c) continue;
        ts.emplace_back(abs(sm[b]-sm[c]));
      }
    }
    sort(ts.begin(),ts.end());
    ts.erase(unique(ts.begin(),ts.end()),ts.end());

    vector<Int> bs;
    for(Int a:as)
      if(!binary_search(ts.begin(),ts.end(),a)) bs.emplace_back(a);

    vector<Int> cand(bs);
    for(Int a:bs){
      for(Int x:ts){
        cand.emplace_back(abs(a-x));
        cand.emplace_back(abs(a+x));
      }
      break;
    }

    cand.emplace_back(0);
    sort(cand.begin(),cand.end());
    cand.erase(unique(cand.begin(),cand.end()),cand.end());

    Int ng=1;
    for(Int x:cand){
      Int ok=1;

      for(Int a:bs)
        ok&=
          binary_search(ts.begin(),ts.end(),abs(a-x))||
          binary_search(ts.begin(),ts.end(),abs(a+x));

      if(ok){
        cout<<x<<endl;
        ng=0;
        break;
      }
    }

    if(ng) cout<<-1<<endl;
  }

  return 0;
}



Measured memory_bytes: 4792
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
   int N,R;
  cin>>N>>R;
  if(N>=10)
  {
    cout<<R<<endl;
  }
  else
  {
    cout<<(R+(100*(10-N)))<<endl;
  }
 
    return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from collections import deque


def main():
    INF = float('inf')
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    if k > (n - 1) * (n - 2) // 2:
        print(-1)
    else:
        ab = [[i, j] for i in range(1, n) for j in range(i + 1, n + 1)]
        m = n - 1 + (n - 1) * (n - 2) // 2 - k
        print(m)
        for i, j in ab[:m]:
            print(i, j)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

vvi g;
int n;

ll dfs(int v, int p=-1){
    ll ret = 0;
    for(auto u : g[v]){
        if(u == p) continue;
        ret += dfs(u, v);
    }
    if(p == -1){
        p = n+1;
    }
    if(v < p){
        ret += ll(v)*(p - v);
    }else{
        ret += ll(v - p)*(n - v + 1);
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i, j, u, v;
    cin >> n;
    g.resize(n+1);
    for(i=0;i<n-1;i++){
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ll ans = dfs(1);
    cout << ans << "\n";
    return 0;
}

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

int main () {

    long long q,h,s,d,n;
    cin >> q >> h >> s >> d >> n;

    h = min(h,q*2);
    s = min(s,h*2);
    d = min(d,s*2);

    long long ans = (n/2)*d;
    ans += (n%2)*s;

    cout << ans << endl;

}


Measured memory_bytes: 256
S = input()
T = input()
s = []
t = []
for i in range(len(S)):
  s.append(S[i])
  t.append(T[i])
flag = 0
if s == t:
  print("Yes")
  flag += 1
else:
  for i in range(len(s)):
    A = s[0]
    s.remove(A)
    s.append(A)
    if s == t:
      print("Yes")
      flag += 1
      break
if flag == 0:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> cnt[105];
int G[105][105];


void solve(int N, int K, int M){
  rep(i,N-1){
    G[i][N-1] = 1;
    G[N-1][i] = 1;
    cnt[N-2-i].push_back(i);
  }
  cnt[0].push_back(N-1);
  int mx = N-2;

  while(K<M){
    if(cnt[mx].size() == 1){
      int a = cnt[mx][0];
      int b = -1;
      rep(i,cnt[mx-1].size()){
        int bb = cnt[mx-1][i];
        if(G[a][bb] == 0){
          b = bb;
          break;
        }
      }
      G[a][b] = 1;
      G[b][a] = 1;
      cnt[mx].clear();
      cnt[mx-1].push_back(a);
      mx--;
    }else{
      int a = -1;
      int b = -1;
      rep(i,cnt[mx].size()){
        rep(j,cnt[mx-1].size()){
          if(i==j) continue;
          int aa = cnt[mx][i];
          int bb = cnt[mx-1][j];
          if(G[aa][bb] == 0){
            a = aa;
            b = bb;
          }
        }
      }
      G[a][b] = 1;
      G[b][a] = 1;
      vector<int> v;
      rep(i,cnt[mx].size()){
        if(cnt[mx][i] == a) continue;
        v.push_back(cnt[mx][i]);
      }
      swap(cnt[mx],v);
      cnt[mx-1].push_back(a);
    }

    M--;
  }

  int E = 0;
  rep(i,N){
    REP(j,i+1,N){
      if(G[i][j] == 1) E++;
    }
  }
  cout << E << endl;
  rep(i,N){
    REP(j,i+1,N){
      if(G[i][j] == 1) cout << i+1 << " " << j+1 << endl;
    }
  }  
}

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

  if(N == 2){
    if(K==0){
      cout << 1 << endl;
      cout << 1 << " " << 2 << endl;
    }else{
      cout << -1 << endl;
    }
  }else{
    int M = (N-1)*(N-2)/2;

    if(M<K){
      cout << -1 << endl;
    }else{
      solve(N, K, M);
    }
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n) {
  if (n == 0) return 1;
  ll r = powMod(x, n / 2);
  if (n % 2 == 0) return (r * r) % MOD;
  return (r * r % MOD) * x % MOD;
}

bool ijv(int i, int j, int h, int w) {
  if (0 <= i && i < h && 0 <= j && j < w) return true;
  return false;
}

char a[2010][2010];
ll s[2010][2010];

int main(void) {

  int n;
  cin >> n;

  ll c[11][11] = {};
  rep(k, n) {
    int d = 0;
    int s[10] = {};
    int l = k + 1;
    while (l > 0) {
      d++;
      s[d - 1] = l % 10;
      l /= 10;
    }
    c[s[0]][s[d - 1]]++;
  }

  ll ans = 0;
  rep(i, 9) rep(j, 9) {
    ans += c[i + 1][j + 1] * c[j + 1][i + 1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

typedef long long ll;

using namespace std;

ll Div(ll a, ll b)
{
  ll ret = a / b;
  return ret >= 0 ? ret : 0;
}

int main()
{
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll x = C*D;
  ll a, b;
  a = C;
  b = D;
  if (a < b)
  {
    ll tmp = b;
    b = a;
    a = tmp;
  }
  ll r = a % b;
  while (r != 0)
  {
    a = b;
    b = r;
    r = a % b;
  }
  ll lcm = x / b;
//  cout << lcm << endl;
  ll divCD = Div(B,C)-Div(A-1,C)+Div(B,D)-Div(A-1,D);
//  cout << divCD << endl;
  ll divL = Div(B,lcm)-Div(A-1,lcm);
//  cout << divL << endl;
  ll ans = B-A+1 - divCD + divL;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main()
{
    IOS;
    in n,k;
    cin >> n >> k;
    in r = n%k;
    in s = k-r;
    cout << min(r,s) << "\n";   
}

Measured memory_bytes: 256
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <tuple>
using namespace std;

int main() {
  string S; cin >> S;
  int K; cin >> K;

  for (int i = 1; i <= S.size(); i++) {
    if (i == K || S[i-1] != '1') {
      cout << S[i-1];
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
  ll n,k;
  cin>>n;
  int ans = INF;
  int v =ceil(sqrt(n));
  rep(i,v+1){
    if(i==0)continue;
    if(n%i==0){
      int x =n/i;
      string s = to_string(x);
      ans= min(ans,(int)s.length());
    }
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<(b);++i)

int n, s;
int ans = 0;

int main() {
	while (true) {
		ans = 0;
		cin >> n >> s;
		if (n == 0)return 0;

		rep(bit, 0, (1 << 10)) {
			vector<int> a;
			rep(i, 0, 10) {
				if (bit & (1 << i))a.push_back(i);
			}

			if (a.size() == n) {
				int sum = 0;
				rep(i, 0, n) {
					sum += a[i];
				}
				if (sum == s)ans++;
				
			}
			
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3168
import math
import itertools

n, d = map(int, input().split())
comb_list = list(range(n))
c = itertools.combinations(comb_list, 2)
l = []
count = 0
for i in range(n):
    array = list(map(int, input().split()))
    l.append(array)

for i, j in c:
    sum = 0
    for k in range(d):
        sum += (l[i][k] - l[j][k])**2
    if math.sqrt(sum) % 1 == 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 4e5 + 20;

int to[maxn] , w[maxn] , val[maxn] , x[maxn] , y[maxn] , z[maxn] , id;

vector<int> adj[maxn];

bool visited[maxn];

void add_edge(int a , int b , int c)
{
	adj[a].pb(id);
	to[id] = b , w[id] = c;
	id++;
}

void dfs(int v)
{
	visited[v] = 1;
	for(auto e : adj[v])
	{
		int u = to[e];
		if(!visited[u])
		{
			val[u] = val[v] + w[e];
			dfs(u);
		}
	}
}

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

	int n , m;
	cin >> n >> m;

	for(int i = 0; i < m; i++)
	{
		int a , b , c;
		cin >> a >> b >> c;
		a-- , b--;

		x[i] = a , y[i] = b , z[i] = c;

		add_edge(a , b , c);
		add_edge(b , a ,-c);
	}

	for(int i = 0; i < n; i++)
		if(!visited[i])
			dfs(i);

	for(int i = 0; i < m; i++)
		if(val[y[i]] - val[x[i]] != z[i])
			return cout << "No" << endl , 0;

	cout << "Yes" << endl;
}


















Measured memory_bytes: 25088
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    for i in range(1,10):
        for j in range(1,10):
            if N==i*j:
                print('Yes')
                return 0

    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952
/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;


class Solution {
public:

	void solve(istream &in, ostream &out) {
		int n;
		in >> n;

		if (n < 1200)
			out << "ABC" << endl;
		else if (n < 2800)
			out << "ARC" << endl;
		else
			out << "AGC" << endl;
	}
};


void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//-------------------------------------------MACROS---------------------------------------------
#define 	TIEMPO_CORRIDA		cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";
#define 	FILES				freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define 	FORIT(it,e)			for(it = e.begin() ; it != e.end() ; it++)
#define 	FOR(i,a,b)			for(i = a ; i < b ; i++)
#define 	RFOR(i,a,b)			for(i = a ; i >= b ;i--)
#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)
#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)
#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define 	to_int(x) 			atoi(x.data())
#define 	to_long(x) 			atoll(x.data())
#define 	ALL(x) 				x.begin(),x.end()
#define 	RALL(x) 			x.rbegin(),x.rend()
typedef 	long long 			ll;
typedef 	pair<int,int> 		pi;
typedef 	pair<ll,ll> 		pl;
const		int 				modN = 1e9+7;
const		double 				PI = 3.1415926535897932384626433832795028841;
//---------------------------------------------------------------------------------------------

string x,y,ans;
int n,m;
int memo[3002][3002];

int dp(int i , int j){
	if(i==n || j == m)  return memo[i][j]=0;
	if(memo[i][j]!=-1) return memo[i][j];
	if(x[i]==y[j]) return memo[i][j]=dp(i+1,j+1)+1;
	return memo[i][j]=max(dp(i+1,j),dp(i,j+1));
}

void build(int i, int j){
	if(i==n || j == m) return;
	if(memo[i][j]-1 == memo[i+1][j+1] && x[i]==y[j]) {
		ans.push_back(x[i]);
		build(i+1,j+1);
		return;
	}  
	if(memo[i][j]== memo[i+1][j] ) {
		build(i+1,j); 
		return;
	}
	if(memo[i][j]== memo[i][j+1]) {
		build(i,j+1);
		return;
	}    
}

int main(){
	fast;
	while(cin >> x>> y){
		ans.clear();
		memset(memo,-1,sizeof memo);
		n = x.size(),m = y.size();
		dp(0,0);
		int i,j;
		
		build(0,0);
		cout <<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 39108
n=int(input())
max1 = 0
max2 = 0
A=[]
for _ in range(n):
    num = int(input())
    if num == max(num, max1):
        max2 = max1
        max1 = num
    elif num == max(num, max2):
        max2 = num
    A.append(num)
for a in A:
    if a == max1:
        print(max2)
    else:
        print(max1)

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

//やってること
//ある頂点aから伸びる辺が一本の場合、伸びている点bにおいて、接続されているaを消去する
//そして、ansの値を1増やす
//もし、辺を持つ頂点の数が、2つの場合、
//どの頂点からも1本も辺が伸びていない場合、探索は終了する
//
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<vector<int> > connect(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        connect[a[i]].push_back(b[i]);
        connect[b[i]].push_back(a[i]);
    }

    int ans = 0;
    while (true) {
        vector<int> grade1;
        for (int i = 0; i < N; ++i) {
            if (connect[i].size() == 0) {
                continue;
            }
            if (connect[i].size() == 1) {
                //次数が1のものを記録する
                grade1.push_back(i);
            }
        }
        if(grade1.size() != 0) {
            for(int g : grade1) {
                //grade1で存在するのは、connect[g].size()==1のときだけ
                //connect[g]はsize() == 1
                //connect[g][0]が繋がった先
                //そこからgを探して削除

                //↓残り一個になったとき, 強制終了
                if(connect[connect[g][0]].size()==0) continue;
                auto itr = std::find(connect[connect[g][0]].begin(), connect[connect[g][0]].end(), g);
                connect[connect[g][0]].erase(itr);
                connect[g].clear();
                ans++;
            }
        } else {
            //次数0のものがなくなっていれば終わり
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int n,c[510],s[510],f[510],*d=c,*t=s,*g=f,i;int main(){scanf("%d",&n);for(;d<c+n-1;++d,++t,++g)scanf("%d%d%d",d,t,g);++(*g=*d=*t=0);for(;i<n;i++)for(int a=0,j=i;j<n||!printf("%d\n",a);)a=(a<s[j]?s[j]:(a/f[j]+(a%f[j]!=0))*f[j])+c[j++];}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<int>v[10000005];
char ch[10005][10005];int kk[10005][10005],flag,p=1000000007;
int dp[90000005],vis[90000005];
int dfs(int x)
{
  //cout<<x<<endl;
  if(vis[x]==1)
  return dp[x];
  vis[x]=1;
  if(x==flag){
    dp[x]=1;
  //cout<<1<<endl;
  return 1;
  }
  int j=0;
  for(auto i : v[x])
  {
    j+=(dfs(i)%p);
  }
  dp[x]=j%p;
  return j%p;
}
int main()
{
  int i,j,n,a,b,m;
  cin>>n>>m;
  flag=(n)*(m);
  flag--;
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    cin>>ch[i][j];
  }
 int k=0;
   for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      kk[i][j]=k;
      k++;
    }
  }
 
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      if(ch[i][j]=='.')
      {
        if(j<m-1)
        {
          if(ch[i][j]=='.'&&ch[i][j+1]=='.')
          v[kk[i][j]].push_back(kk[i][j+1]);
          //cout<<i<<" "<<j<<"  "<<i<<" "<<j+1<<" "<<kk[i][j]<<endl;}  
        }
        if(i<n-1)
        {
          if(ch[i][j]=='.'&&ch[i+1][j]=='.')
          v[kk[i][j]].push_back(kk[i+1][j]);  
          //cout<<i<<" "<<j<<"  "<<i+1<<" "<<j<<" "<<kk[i][j]<<endl;}
        }
      }
    }
  }
  cout<<(dfs(0)%p);
}


Measured memory_bytes: 331520
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int N, K;
ll A[int(1e5 + 5)], L[int(1e5 + 5)], R[int(1e5 + 5)], sum[int(1e5 + 5)];

int main(){
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) scanf("%lld", A + i);

  for (int i = 1; i <= N; i++){
    sum[i] = sum[i - 1] + A[i];
    L[i] = L[i - 1] + max(0ll, A[i]);
  }
  for (int i = N; i >= 0; i--){
    R[i] = R[i + 1] + max(0ll, A[i]);
  }

  ll ans = 0;
  for (int i = 0; i + K <= N; i++){
    ll now = max(0ll, sum[i + K] - sum[i]);
    now += L[i] + R[i + K + 1];
    ans = max(ans, now);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3456
import Debug.Trace

solve0 as b = sum $ zipWith (\a i->abs (a-(b+i))) as [1,2..]

solve as minB maxB
  | abs(minB - maxB) < 3 = minimum $ map (solve0 as) [minB, minB+1, minB+2]
  | lbs < rbs = solve as minB rb
  | otherwise = solve as lb maxB
  where lb = (minB*2+maxB)`div`3
        rb = (minB+maxB*2)`div`3
        lbs = solve0 as lb
        rbs = solve0 as rb

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  let bs = zipWith (-) as [1..]
      maxB = maximum bs
      minB = minimum bs
  print $ solve as minB maxB


Measured memory_bytes: 109948
#include<stdio.h>
int  main(void)
{
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a==b)
   printf("%d",a+b);
  if(a>b)
    printf("%d",a+a-1);
  if(a<b)
    printf("%d",b+b-1);
  return 0;}

Measured memory_bytes: 128
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

ls = sorted(a, key = lambda x: x[1])

def abc(a):
    time = 0
    for job in a:
        time += job[0]
        if time > job[1]:
            return 'No'
    return 'Yes'

print(abc(ls))


Measured memory_bytes: 55192
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	char c;
	cin >> c;
	if (islower(c)) cout << "a" << endl;
	else cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 3616
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    double pai = 1, sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        pai *= a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        sum += pai / a[i];
    }
    double ans = pai / sum;
    printf("%.14f\n", ans);
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
d = defaultdict(int)

for i in range(N):
    S = input()
    d[S] += 1

print(len(d.keys()))

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

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

int main() {
    string a, b;
    cin >> a >> b;
    int x = a.size() - b.size();
    if (x > 0 || (x == 0) && (a > b))
        cout << "GREATER" << endl;
    else if (x < 0 || (x == 0) && (a < b))
        cout << "LESS" << endl;
    else
        cout << "EQUAL" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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 COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    ll n=s.size();
    ll res=0;
    for(ll bit=0;bit<(1<<(n-1));bit++){
        ll tmp=0;
        rep(i,n-1){
            tmp*=10;
            tmp+=s[i]-'0';
            if(bit & (1<<i)) {
                res+=tmp;
                tmp=0;
            }
        }
        tmp*=10;
        tmp+=s.back()-'0';
        res+=tmp;
    }
    cout<<res<<endl;
    return 0;
}

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

int main(){
  ll k,a,b;
  cin >> k >> a >> b;
  ll bis = 1;
  ll m = 0;
  rep(i,k){
    if( i == k-1 ){
      if( m != 0 ){
        m--;
        bis += b;
      }else{
        bis++;
      }
      break;
    }
    if( a <= b ){
      if( bis < a && m == 0 ){
        bis++;
        //cout << 'a' << endl;
      }else if( m != 0 ){
        m--;
        bis += b;
        //cout << 'b' << endl;
      }else if( bis >= a && m == 0 ){
        bis -= a;
        m++;
        //cout << 'c' << endl;
      }else{
        bis++;
        //cout << 'd' << endl;
      }
    }else{
      bis++;
    }
  }
  cout << max(bis,k+1) << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 1002;

int n, m, a, b, s[MM][MM];

int main(){
    
    scan(n, m, a, b);
    swap(a, b);
    
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++)
            s[i][j] = 1;
    }
    
    for(int i = a; i < n; i++){
        for(int j = b; j < m; j++)
            s[i][j] = 1;
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++)
            pc(s[i][j]+'0');
        pc(10);
    }
    
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;




int main() {
	set<int> s;
	int a[200000] = { 0 }, x, ans = 0;
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x;
		a[x]++;
		s.insert(x);
	}
	if (s.size() <= k) cout << "0" << endl;
	else {
		sort(a, a + 200000);
		int index = lower_bound(a,a+200000,1) - a;
		for (int i = index; i < index + s.size() - k; i++) ans += a[i];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 10368
def resolve():
    '''
    code here
    '''
    import sys

    sys.setrecursionlimit(100000000)
    N = int(input())

    memo = [0 for _ in range(N+1)]

    def fina(n):
        if n <= 1:
            memo[n] = 1
            return 1

        if memo[n] != 0:
            return memo[n]

        memo[n-1] = fina(n-1)
        memo[n-2] = fina(n-2)        
        memo[n] = memo[n-1] + memo[n-2]

        return memo[n]
    
    print(fina(N))



if __name__ == "__main__":
    resolve()



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

const int mod=1e9+7;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return res;
}
ll inv(ll x){

    return power(x,mod-2);
}
vector<ll>g[200020];
int a[44444],b[44444];
vector<ll>v1,v2;
int main(){
    ll n,i,j,k,x,y,z,t,m;
    string s;
    cin>>s;
    if(s=="AAA"||s=="BBB")cout<<"No";
    else cout<<"Yes";
}







Measured memory_bytes: 4992
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] num = new int[5];
		
		for(int i = 0; i < num.length; i++){
			num[i] = sc.nextInt();
		}
		
		java.util.Arrays.sort(num);
		
		for(int i = num.length - 1; i >= 0; i--){
			if(i > 0) System.out.print(num[i] + " ");
			else System.out.println(num[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#include <queue>
#include <stack>
#define mod 998244353
#define pb(x) push_back(x)
#define N 110000
using namespace std;
int main()
{
    long long x,y;
    cin>>x>>y;
    if (x%y==0)puts("-1");
    else cout<<(y-1)*x<<endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split(" ")))

a.sort(reverse=True)

al = 0
bo = 0

if N % 2 == 1:
	N -= 1
	al += a[-1]

for i in range(0,N,2):
	al += a[i]
	bo += a[i+1]

print(al-bo)



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#define ll long long

using namespace std;

long long MOD = 1000000007;

double e=0.000000001;
int N;

bool judge(double cx, double cy, double r2, vector<vector<double>> &circ){
    for(int i=0; i<N; i++){
        double x=circ[i][0];
        double y=circ[i][1];
        if((x-cx)*(x-cx)+(y-cy)*(y-cy)>r2+e){
            return false;
        }
    }
    return true;
}

int main(){
    cin >> N;
    vector<vector<double>> circles(N,vector<double>(2,0.));
    for(auto &c:circles){
        cin >> c[0] >> c[1];
    }

    double ans=MOD;

    for(int i=0; i<N; i++){
        for(int j=0; j<i; j++){
            double x1=circles[i][0];
            double y1=circles[i][1];
            double x2=circles[j][0];
            double y2=circles[j][1];

            double cx=(x1+x2)/2;
            double cy=(y1+y2)/2;
            double r2=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/4;

            if(judge(cx,cy,r2,circles)){
                ans=min(ans,sqrt(r2));
            }

            for(int k=0; k<j; k++){
                double x3=circles[k][0];
                double y3=circles[k][1];

                if((abs(x2-x1)<e && abs(x3-x2)<e) || abs(y2-y1)<e && abs(y3-y2)<e)continue;
                cy=((x3-x1)*(x1*x1+y1*y1-x2*x2-y2*y2)-(x2-x1)*(x1*x1+y1*y1-x3*x3-y3*y3))/(2*(x3-x1)*(y1-y2)-2*(x2-x1)*(y1-y3));
                if((x2-x1)!=0){
                    cx=(2*(y1-y2)*cy-x1*x1-y1*y1+x2*x2+y2*y2)/(2*(x2-x1));
                }else{
                    cx=(2*(y1-y3)*cy-x1*x1-y1*y1+x3*x3+y3*y3)/(2*(x3-x1));
                }
                r2=(cx-x1)*(cx-x1)+(cy-y1)*(cy-y1);
                if(judge(cx,cy,r2,circles)){
                    ans=min(ans,sqrt(r2));
                }
            }
        }
    }
    cout << setprecision(10) << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> gr[N];
int dp[N][3];
void dfs(int v, int par) {
	for (auto u : gr[v]) 
		if (u != par)
			dfs(u, v);
	int ps = 0, z = 0;
	for (auto u : gr[v]) {
		if (u != par) {
			ps += dp[u][1];
			if (dp[u][1] == dp[u][0])
				z = 1;
		}
	}
	dp[v][0] = ps, dp[v][1] = ps + z;
	return;
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[x].push_back(y), gr[y].push_back(x);
	}
	dfs(0, 0);
	if (dp[0][1] != (n + 1) / 2)
		cout << "First";
	else
		cout << "Second";
	return 0;
}


Measured memory_bytes: 7552
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader( System.in ));
        int x[]= new int[10];
        int n;
        for( int i = 0 ; i < 10 ; i++ )x[i] = Integer.parseInt( br.readLine());
        for(int i=0;i<3;i++){
            for(int j=i;j<10;j++){
                if(x[i]<x[j]){
                    n=x[i];
                    x[i]=x[j];
                    x[j]=n;
                }
            }
        }
        for(int i = 0 ; i < 3 ; i++ )System.out.println( x[i] );
    }
}



Measured memory_bytes: 24352
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int>a(n),presum(n) , postsum(n);
for(int i=0;i<n;i++)
    cin>>a[i];
long long    sum=0;
for(int i=0;i<n;i++){

    sum+=a[i];
    presum[i]=sum;


}
sum=0;
for(int i=n-1;i>=0;i--){

    sum+=a[i];
    postsum[i]=sum;


}
long long min = LLONG_MAX;
for(int i=0;i<n-1;i++){
    if(abs(presum[i] - postsum[i+1]) < min)
    min = abs(presum[i] - postsum[i+1]);
}

cout<<min<<endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
K = []
A = []
for _ in range(N):
    row = list(map(int,input().split()))
    K.append(row[0])
    A.append(row[1:])

likedByAll = [True for _ in range(M)]
for i in range(N):
    for m in range(1,M+1):
        if m not in A[i]:
            likedByAll[m-1] = False
ans = 0
for liked in likedByAll:
    if liked:
        ans += 1
print(ans)
        

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll N, M;
	cin >> N >> M;
	ll A[N];
	ll sum = 0;
	for (ll i = 0;i < N;i++) {
		cin >> A[i];
		sum += A[i];
	}
	double sup = double(sum) / (4 * M);
	ll cnt = 0;
	rep(i,0,N) {
		if (double(A[i]) >= sup) cnt++;
	}
	if (cnt >= M) cout << "Yes" << endl;
	else cout << "No" << endl;
	// cout << sum << " " << sup << " " << cnt << endl;
	return 0;
}


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

int main(){
    int n, k, i, a, m, s = 0;
    cin >> n >> k;
    for(i=0; i<n; i++){
        cin >> a;
        if(a == 1){
            m = i;
        }
    }
    s += m/(k-1);
    s += (n-m-1)/(k-1);
    if(m%(k-1) + (n-m-1)%(k-1) == 0){
        ;
    }else if(m%(k-1) + (n-m-1)%(k-1) <= k-1){
        s += 1;
    }else{
        s += 2;
    }
    cout << s;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  LL H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  
  for (int i = N - 1; i > 0; i--) {
    if (H[i - 1] > H[i]) {H[i - 1]--;}
  }
  
  bool ans = true;
  for (int i = N - 1; i > 0; i--) {
    if (H[i - 1] > H[i]) {ans = false;}
  }
  
  if (ans) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    K, T = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()]
    print(max(0, max(A)-(sum(A)-max(A))-1))

if __name__ == '__main__':
     main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(void){
  int K,N;
  scanf("%d %d\n",&K,&N);
  if((K>=2 && K<=1000000) && (N>=2 && N<=200000))
  {
    int A[N];
    int i;
    scanf("%d ",&A[0]);
    if(A[0]<0 || A[0]>=K)
      return 0;
    for(i=1;i<N;i++)
    {
      scanf("%d ",&A[i]);
      if((A[i]<0 || A[i]>=K) || A[i]<=A[i-1])
        return 0;
    }
    int B[N],max=0;
    for(i=0;i<N-1;i++)
    {
      B[i]=A[i+1]-A[i];
      if(B[i]>max)
        max=B[i];
    }
    B[N-1]=K-A[N-1]+A[0];
    if(B[N-1]>max)
      max=B[N-1];
    int r=K-max;
    printf("%d",r);
  }
  return 0;
}


Measured memory_bytes: 1664
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
//use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    proconio::input! {
        S:proconio::marker::Chars
    }
    let l = S.len();
    for i in 0..(l - 1) / 2 {
        if S[i] != S[l - 1 - i] {
            println!("No");
            return;
        }
    }
    for i in 0..(l - 1) / 4 + 1 {
        if S[i] != S[(l - 1) / 2 - 1 - i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2100
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
    	int n=sc.nextInt();
    	int[] x=new int[n];
    	int t = 0;
    	for(int i=0;i<n;i++) {
    		x[i] = sc.nextInt();
    		t+=x[i];
    	}
    	t/=n;
    	long sum = 0;
    	long sum1= 0;
    	long sum2 = 0;
    	for(int i=0;i<n;i++) {
    		sum+=(int)Math.pow(x[i]-t, 2);
    	}
    	for(int i=0;i<n;i++) {
    		sum1+=(int)Math.pow(x[i]-t-1, 2);
    	}
    	for(int i=0;i<n;i++) {
    		sum2+=(int)Math.pow(x[i]-t+1, 2);
    	}
    	System.out.println(Math.min(Math.min(sum, sum1), sum2));
	}
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i = 0;
	char s[100001] = {0};
	int slong;
	
	char d[]  = "dream";
	char dr[] = "dreamer";
	char e[]  = "erase";
	char er[] = "eraser";
	
	scanf("%s", s);
	slong = strlen(s);
	
	while (1)
	{
		int hantei = i;
		
		if (strncmp(s + i, d, 5) == 0)
		{
			if ((strncmp(s + i, dr, 7) == 0) && (strncmp(s + i + 5, e, 5) != 0))
				i += 7;
			else
				i += 5;
		}
		else if (strncmp(s + i, e, 5) == 0)
		{
			if (strncmp(s + i, er, 6) == 0)
				i += 6;
			else
				i += 5;
		}
		
		if (hantei == i)
			break;
	}
	
	if (i == slong)
		printf("YES");
	else
		printf("NO");
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 100000009;
const int mod = 10007;
char op[109];
int main()
{
	scanf("%s", op);
	int num = 0;
	int n = strlen(op);
	for (int i = 0; i < n&&i < n - 1 - i; ++i) {
		if (op[i] != op[n - 1 - i]) ++num;
	}
	cout << num;
	//system("pause");
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n%10==3) cout << "bon";
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout << "pon";
  else cout << "hon";
  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>

int main(){
	
	char s[11];
	char t[11];
	char u[11];
	int a;
	int b;
	scanf("%s %s\n",&s,&t);
	scanf("%d %d\n",&a,&b);
	scanf("%s",&u);
	
	if(strcmp(s,t) == 0){
		printf("eror!");
	}
	else if(strcmp(s,u) == 0){
		printf("%d %d",a-1,b);
	}
	else if(strcmp(t,u) == 0){
		printf("%d %d",a,b-1);
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1680
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <string>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){

    ll a;
    cin >> a;

    p(a + a*a + a*a*a);

    return 0;
}


Measured memory_bytes: 3188
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var x = next();
  var y = next();
  var ans = xArray(0,n-1);
  var map = xArray(1e9,n+2,n+2);
  for(var i = 1; i <= n; i++){
    map[i][i] = 0;
    map[i][i+1] = 1;
    map[i][i-1] = 1;
    if(i === x)map[i][y] = map[y][i] = 1;
  }
  for(var i = 1; i <= n; i++){
    for(var j = i+1; j <= n; j++){
      map[i][j] = Math.min(map[i][j-1],map[i][j+1],map[i-1][j],map[i+1][j],map[i][j]-1)+1;
    }
  }
  for(var i = n-1; i > 0; i--){
    for(var j = n; j > i; j--){
      map[i][j] = Math.min(map[i][j-1],map[i][j+1],map[i-1][j],map[i+1][j],map[i][j]-1)+1;
      ans[map[i][j]-1]++;
    }
  }
  return ans.join("\n")
}

Measured memory_bytes: 63460
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var X = input[0];
            var N = input[1];
            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }
            var p = ReadArrayInt();
            var ans = X;
            var low = X - 1;
            var high = X + 1;
            if (p.Contains(X))
            {
                do
                {
                    if (!p.Contains(low))
                    {
                        ans = low;
                        break;
                    }
                    else if (!p.Contains(high))
                    {
                        ans = high;
                        break;
                    }
                    low--;
                    high++;
                } while (true);
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 28252
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    # divisors.sort()
    return divisors

a,b = map(int, input().split())
l = make_divisors(b)
l.sort(reverse=False)
res = 1
#print(l)
for x in l:
    if x <= b//a:
        res = max(x, res)
print(res)


Measured memory_bytes: 38640
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

ll flac[2000010];

ll modinv(ll a) {
  ll M = MOD, b = M, u = 1, v = 0;
  while (b)
    u -= a / b * v, swap(u, v), a %= b, swap(a, b);
  return (u % M + M) % M;
}

ll foo(ll i, ll j) {
  ll ans = flac[i + j];
  ans *= modinv(flac[i]);
  ans %= MOD;
  ans *= modinv(flac[j]);
  ans %= MOD;
  return ans;
}

void solve() {
  ll r1, c1, r2, c2;
  cin >>  r1 >> c1 >> r2 >> c2;

  flac[0] = 1;
  rep (i, 2000010) {
    if (i == 0) continue;
    flac[i] = (flac[i-1] * i) % MOD;
  }

  ll ans = foo(r2 + 1, c2 + 1);
  ans -= foo(r2 + 1, c1);
  ans -= foo(r1, c2 + 1);
  ans += foo(r1, c1);

  ans %= MOD;
  ans += MOD;
  ans %= MOD;

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 15872