akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int ceil(int a, int b) {
	return (a+b-1)/b;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, n, w;
    cin >> h >> w >> n;
    int res = min(ceil(n, h), ceil(n, w));
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define lu unsigned long long int
#define pi pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define be begin
#define sz(a) (ll)(a.size())
#define INF 1e18
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

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

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }


void solve(ll T){
	ll l,r,d;
	cin>>l>>r>>d;
	cout << r/d - (l-1)/d << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// std::cout << std::unitbuf;
	ll T=1;
	// cin>>T;
	for(ll t=1;t<=T;t++){
		solve(t);
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(a>0&&c>0){
		a-=d;
		c-=b;
	}
	if(c<=0) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int n;
char c[27]={' ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char find(char k){
	int m=0;
	for(int i=1;i<=26;i++){
		if(c[i]==k){
			m=i;
			break;
		}
	}
	m+=n;
	if(m>26) m=m-26;
	return c[m];
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	string s,ans="";
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++){
		ans+=find(s[i]);
	}
	cout<<ans;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int iv[n];
  for(int i=0; i<n; ++i){
    cin >> iv[i];
  }
  int max = iv[0];
  int sum = iv[0];
  for(int i=1; i<n; ++i){
    sum += iv[i];
    while(max * (i+1) > sum){
      --max;
    }
  }
  cout << max << endl;
}



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

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i <= n; i++) for(int j = 0; j <= m; j++){
        if(i * j + (n - i) * (m - j) == k){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;

    scanf("%d%d", &a, &b);
    if (a < b) printf("a < b\n");
    else if (a > b) printf("a > b\n");
    else printf("a == b\n");
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  int cntb[201010];
  for (int i = 2; i <= n; i++) {
    int boss;
    cin >> boss;
    cntb[boss]++;
  }
  for (int i = 1; i <= n; i++)
    cout << cntb[i] << endl;
}

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

int main() {
 int n,k,ans=0;
  cin >> n >> k;
  int x[n];
  for(int i=0;i<n;i++){
  cin >> x[i];
  
    if(k-x[i]>=x[i])ans+=2*x[i];
    else ans+=2*(k-x[i]);
  }
  
  cout << ans << endl;
  
}

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

int main(){
    vector<vector<int>> a(3, vector<int>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    int N; cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N; i++)
    {
        cin >> b[i];
    }
    vector<vector<int>> ans(3, vector<int>(3));
    for (int k = 0; k < N; k++)
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if(a[i][j] == b[k]) ans[i][j] = 1;
            }
        }
    }
    for (int i = 0; i < 3; i++)
    {
        if(ans[i][0] == 1 && ans[i][1] == 1 && ans[i][2] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++)
    {
        if (ans[0][i] == 1 && ans[1][i] == 1 && ans[2][i] == 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (ans[0][0] == 1 && ans[1][1] == 1 && ans[2][2] == 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (ans[0][2] == 1 && ans[1][1] == 1 && ans[2][0] == 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;

    return 0;
}

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

int main() {
  int L, R;
  cin >> L >> R;
  int64_t ans = 1000000000;
  if(R-L > 2019*2){
    ans = 0;
  }
  else{
    vector<int64_t> vec(R-L+1);
    vector<int64_t> vec2(R-L+1);
    for(int i=0; i<R-L+1; i++){
      vec.at(i) = (L+i)%2019;
      vec2.at(i) = (L+i)%2019;
    }
    for(int i=0; i<R-L+1; i++){
      for(int j=0; j<R-L+1; j++){
        if(i == j){
          continue;
        }
        int64_t tmp = vec.at(i)*vec2.at(j);
        while(tmp > 2018){
          tmp %= 2019;
        }
        ans = min(ans,tmp);
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;
template<typename T, T mod>
class Modint {
private:
  T x;

public:
  Modint(): x((T)0) {}
  Modint(T y): x(y >= 0? y % mod: (mod - (-y) % mod) % mod) {}

  T get() {
    return x;
  }

  Modint &operator+=(const Modint &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  Modint &operator-=(const Modint &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  Modint &operator*=(const Modint &p) {
    x = x * p.x % mod;
    return *this;
  }

  Modint &operator/=(const Modint &p) {
    *this *= p.inverse();
    return *this;
  }

  Modint operator-() const { return Modint(-x); }
  Modint operator+(const Modint &p) const {return Modint(*this) += p; }
  Modint operator-(const Modint &p) const {return Modint(*this) -= p; }
  Modint operator*(const Modint &p) const {return Modint(*this) *= p; }
  Modint operator/(const Modint &p) const {return Modint(*this) /= p; }

  bool operator==(const Modint &p) const { return x == p.x; }
  bool operator!=(const Modint &p) const { return x != p.x; }

  Modint inverse() const {
    T a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return Modint(u);
  }

  Modint pow(int e) const {
    T a = 1, p = x;
    while(e > 0) {
      if (e % 2 == 0) {
	p = (p * p) % mod;
	e /= 2;
      } else {
	a = (a * p) % mod;
	e--;
      }
    }
    return Modint(a);
  }
};

constexpr long long MOD = 998244353;

using mi = Modint<long long, MOD>;

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

  vector<int> l(k), r(k);
  for (int i = 0; i < k; ++i) cin >> l[i] >> r[i];

  vector<mi> dp(n + 1, 0);
  vector<mi> sums(n + 1, 0);
  dp[1] = 1;
  sums[1] = 1;

  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      int left_idx = max(1, i - r[j]);
      int right_idx = i - l[j];
      if (right_idx  < 0) continue;
      dp[i] += sums[right_idx] - sums[left_idx - 1];
    }
    sums[i] = sums[i - 1] + dp[i];
  }
  cout << dp[n].get() << '\n';
  return 0;
}



Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  ull n, a, b;
  cin >> n >> a >> b;
  if (a == 0) cout << 0 << endl;
  else {
    if (n <= a) cout << n << endl;
    else if (n <= (a + b)) cout << a << endl;
    else {
      ull tmp1 = n / (a + b);
      ull tmp2 = n % (a + b);
      if (tmp2 <= a) cout << tmp1 * a + tmp2 << endl;
      else cout << tmp1 * a + a << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i;
    char str;
    int a[26] = {0};
    while ((str = getchar()) != EOF){
        if(str == '\0'){
            break;
        }
        if('A' <= str && str <= 'Z'){
            str = str + 32;
        }
        if('a' <= str && str <= 'z'){
            a[str - 'a']++;
        }
    }
    for(i = 0; i < 26; i++){
        printf("%c : %d\n", 'a'+i, a[i]);
    }
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll inf=1e18;
const ll maxs = 201;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define line() cout<<endl;
#define fr(i,b) for(ll i=0;i<b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll lcm(ll a,ll b)
{
    return a*b/__gcd(a,b);
}


int main()
{
    fastio();
    
     ll t=1;
     //cin>>t;
     while(t--)
     {
        ll n,k;
        cin>>n>>k;
        ll a[n];
        fr(i,n)
            cin>>a[i];
        ll dp[n];
        for(ll i=0;i<n;i++)
            dp[i]=inf;
        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);
        for(ll i=2;i<n;i++)
        {
            ll start = max(0ll,i-k);
            for(ll j=start;j<i;j++)
              dp[i] = min( dp[i] ,dp[j]+abs(a[j]-a[i]));
        }
        cout<<dp[n-1];
     }
    return 0;
}



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

int main()
{
    int n,ck=0,i;
    cin>>n;
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(n%2 == 1)
    {
        cout<<"No"<<endl;
        return 0;
    }
    for(i=0; i<s.size()-1; i=i+2)
    {
        if(s[i]==s[i+1])
        {

        }
        else
        {
            ck = 1;
            break;
        }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

int main(){
    ll h, w, ans;
    cin >> h >> w;
    if(h == 1 || w == 1){
        ans = 1;
    }else{
    if(h % 2 != 0 && w % 2 != 0){
        ans = (h * w + 1) / 2;
    }else{
        ans = h * w / 2;
    }
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int a,b;
    cin>>a>>b;
    if((a-b)%2==0)cout<<(a+b)/2;
    else cout<<"IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 384
PROGRAM Tag
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      integer(prec) :: a,b,v,w,t
      integer(prec) :: dist,Vsub
      
      read*,a,v
      read*,b,w
      read*,t
      
      dist = abs( a-b )
      Vsub = v-w
      
      
      if( dist<=Vsub*t )then
        print'(A)','YES'
      else
        print'(A)','NO'
      end if
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

Measured memory_bytes: 2912
using System;
class Program
{
  static void Main(string[] args)
  {
    string S = Console.ReadLine();
    string A,T,G,C;
    A = "A";
    T = "T";
    G = "G";
    C = "C";
    
    if(S == A) Console.WriteLine("T");
    else if(S == T) Console.WriteLine("A");
    else if(S == G) Console.WriteLine("C");
    else if(S == C) Console.WriteLine("G");
  }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

char s[20];
char r[20] = {"CODEFESTIVAL2016"};
int x;

int main(){
	scanf("%s" , s);
	repp(i,0,16){
		if(s[i] != r[i]) ++x;
	}
	printf("%d\n" , x);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
struct edge{
	int to,cost;
};
class DIA{//diameter of tree
	public:
	vector<vector<edge> >G;
	vi d;
	vector<bool>vis;
	int n;
	DIA(int size){
		n=size;
		G=vector<vector<edge> >(n);
		d=vi(n);
		vector<bool>vis(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);G[b].pb(ee);
	}
	void bfs(int s){
		d=vi(n,inf);
		queue<int>q;
		q.push(s);
		d[s]=0;
		int u;
		while(!q.empty()){
			u=q.front();q.pop();
			rep(i,G[u].size()){
				edge e=G[u][i];
				if(d[e.to]==inf){
					d[e.to]=d[u]+e.cost;
					q.push(e.to);
				}
			}
		}
	}
	void dia(){
		bfs(0);
		int maxv=0,tgt=0;
		rep(i,n)if(d[i]!=inf&&maxv<d[i]){
			maxv=d[i];
			tgt=i;
		}
		bfs(tgt);
		maxv=0;
		rep(i,n)if(d[i]!=inf)maxv=max(maxv,d[i]);
		cout<<maxv<<endl;
	}
};
int main(){
	int n;
	cin>>n;
	DIA dia(n+10);
	rep(i,n-1){
		int s,t,w;
		cin>>s>>t>>w;
		dia.add_edge(s,t,w);
	}
	dia.dia();
}

Measured memory_bytes: 8212
#include<bits/stdc++.h>
using namespace std;
long long a;
long double b;
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "a", stdout);
    // #endif
    cin >> a >> b;
    cout << (long long)(a * b) << "\n";
    return 0;
}

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

string S, T, A;

bool solve(void) {
	int ls = S.length();
	int lt = T.length();
	bool ret = false;
	if (lt > ls)
		return ret;
	for (int d = 0; d <= ls - lt; ++d) {
		A = S;
		int ps_end = ls - 1 - d;
		int ps_stt = ps_end - lt + 1;
		bool flag = true;
		for (int i = ps_stt, j = 0; i <= ps_end; ++i, ++j) {
			if (S[i] == '?')
				A[i] = T[j];
			else {
				if (S[i] == T[j])
					A[i] = T[j];
				else {
					flag = false;
					break;
				}
			}
		}
		if (flag) {
			ret = true;
			break;
		}
	}
	if (ret) {
		for (int i = 0; i < ls; ++i) {
			if (A[i] == '?')
				A[i] = 'a';
		}
	}
	return ret;
}

int main(void) {
	cin >> S >> T;
	bool ans = solve();

	if (ans)
		cout << A << '\n';
	else
		cout << "UNRESTORABLE\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a, b, c, d, e, x[4], f;
int main() {
	while (true) {
		x[0] = 0;
		x[1] = 0;
		x[2] = 0;
		x[3] = 0;
		cin >> a;
		if (a == 0) { break; }
		x[a]++;
		cin >> b >> c >> d >> e;
		x[b]++;
		x[c]++;
		x[d]++;
		x[e]++;
		if (x[1] >= 1 && x[2] >= 1 && x[3] >= 1) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else if (x[1] >= 5 || x[2] >= 5 || x[3] >= 5) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else {
			if (x[2] == 0) {
				if (a == 1) { a = 4; }
				if (b == 1) { b = 4; }
				if (c == 1) { c = 4; }
				if (d == 1) { d = 4; }
				if (e == 1) { e = 4; }
			}
			if (x[1] == 0) { f = 2; }
			if (x[2] == 0) { f = 3; }
			if (x[3] == 0) { f = 1; }
			if (a == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (b == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (c == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (d == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (e == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
		}
	}
	return 0;
}

Measured memory_bytes: 1156
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    prefixSum2(A)

    var min = Long.MAX_VALUE

    var partitionPositionForL = 0
    var partitionPositionForR = 2

    fun LMeetsConditionOnNext(partionPosition: Int, center: Int) : Boolean {
        val current = partionPosition
        val currentLeftSum = A.get(current)
        val currentRightSum = A.get(center - 1) - A.get(current)
        val currentDiff = Math.abs(currentLeftSum - currentRightSum)

        val next = partionPosition + 1
        val nextLeftSum = A.get(next)
        val nextRightSum = A.get(center - 1) - A.get(next)
        val nextDiff = Math.abs(nextLeftSum - nextRightSum)

        return nextDiff < currentDiff
    }

    fun RMeetsConditionOnNext(partionPosition: Int, center: Int) : Boolean {
        val current = partionPosition
        val currentLeftSum = A.get(current) - A.get(center - 1)
        val currentRightSum = A.get(N - 1) - A.get(current)
        val currentDiff = Math.abs(currentLeftSum - currentRightSum)

        val next = partionPosition + 1
        val nextLeftSum = A.get(next) - A.get(center - 1)
        val nextRightSum = A.get(N - 1) - A.get(next)
        val nextDiff = Math.abs(nextLeftSum - nextRightSum)

        return nextDiff < currentDiff
    }

    for (center in 2..N-2) {
        //val L = A.subList(0, center)
        //val R = A.subList(center, N)
        // Find the optimized partition for L
        while (partitionPositionForL < center - 1 && LMeetsConditionOnNext(partitionPositionForL, center)) {
            partitionPositionForL++
        }

        // Find the optimized partition for L
        while (partitionPositionForR < N - 1 && RMeetsConditionOnNext(partitionPositionForR, center)) {
            partitionPositionForR++
        }

        val sumP = A.get(partitionPositionForL)
        val sumQ = A.get(center - 1) - A.get(partitionPositionForL)
        val sumR = A.get(partitionPositionForR) - A.get(center - 1)
        val sumS = A.get(N - 1) - A.get(partitionPositionForR)
        val list = listOf<Long>(sumP, sumQ, sumR, sumS).toMutableList()
        list.sort()
        val result = list.last() - list.first()
        min = Math.min(min, result)


        // PREPARE FOR INCREMENTING CENTER
        if (center == partitionPositionForR) {
            partitionPositionForR++
        }
    }

    println(min)
}

fun prefixSum2(A: MutableList<Long>) {
    for(i in 1..(A.size - 1)) {
        A.set(i, A.get(i) + A.get(i - 1))
    }
}


Measured memory_bytes: 102120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            long n = NextLong;
            var hurui = Enumerable.Repeat(true, 1000001).ToArray();
            hurui[0] = false;
            hurui[1] = false;
            var list = new List<long>();
            int count = 0;

            for (int i = 2; i <= 1000000; i++)
            {
                while (i <= 1000000 && !hurui[i]) { i++; }

                for (int j = 2 * i; j <= 1000000; j += i)
                {
                    hurui[j] = false;
                }
            }

            for (int i = 0; i <= 1000000; i++)
            {
                if (hurui[i])
                {
                    long tmp = i;
                    while (tmp <= 1000000000000)
                    {
                        list.Add(tmp);
                        tmp *= i;
                    }
                }
            }

            list.Sort();

            foreach (var num in list)
            {
                if (n % num == 0)
                {
                    n /= num;
                    count++;
                }
            }

            if (n >= 1000000) count++;
            System.Console.WriteLine(count);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 32716
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = ((int)(n) - 1); i >= 0; i--)
#define repn(i, n) for(int i = 1; i <= (int)(n); i++)
#define reprn(i, n) for(int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LARGE_PRIME_NUM (1e9+7)
typedef long long ll;

#include <iostream>
#include <array>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int s = 0;
	rep(i, k) {
		if (i < a) {
			s++;
		} else if (i < a + b) {

		} else if (i < a + b + c) {
			s--;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3648
import numpy as np
import sys

N = int(input())
A = input().split(' ')

an = np.array(A, dtype=np.int64)

chk = 0
for i in range(0,N):
   chk = chk ^ an[i] 

if(chk == 0):
   print('Yes')
else:
   print('No')
  





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

int main() {
    int n, max_w;
    scanf("%d %d", &n, &max_w);
    vector<pair<int, int>> item(n+1);
    rep(i, n+1) {
        if (i == 0) continue;
        scanf("%d %d", &item[i].first, &item[i].second);
    }
    vector<vector<int>> c(n+1,vector<int>(max_w+1));
    rep(i, n+1) {
        rep(w, max_w+1) {
            if (i == 0 || w == 0) {
                c[i][w] = 0;
            } else {
                if (w-item[i].second < 0) c[i][w] = c[i-1][w];
                else c[i][w] = max(c[i-1][w-item[i].second]+item[i].first, c[i-1][w]);
            }
            // printf("%d ", c[i][w]);
        }
        // printf("\n");
    }
    printf("%d\n", c[n][max_w]);
}


Measured memory_bytes: 6844
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    long long int ans=0;
    for(int i=0; i<(1<<(str.size()-1)); i++) {
        long long int tmp=0;
        for(int n=0; n<str.size()-1; n++) {
            if(i & (1<<n)) {
                tmp *= 10;
                tmp += (long long int)(str[n]-'0');
                ans += tmp;
                tmp = 0;
            } else {
                tmp *= 10;
                tmp += (long long int)(str[n]-'0');
            }
        }
        ans += tmp*10;
        ans += (long long int)(str[str.size()-1]-'0');
    }
    cout << ans << endl;



    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=3005,mod=998244353;
ll dp[N][N];
int32_t main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    dp[a][b]=1;
    for (int i=a+1;i<=c;i++){
        dp[i][b]=dp[i-1][b]*b%mod;
    }
    for (int i=b+1;i<=d;i++){
        dp[a][i]=dp[a][i-1]*a%mod;
    }
    for (int i=a+1;i<=c;i++){
        for (int j=b+1;j<=d;j++){
            dp[i][j]=dp[i-1][j]*j%mod+dp[i][j-1]*i%mod-dp[i-1][j-1]*(i-1)*(j-1)%mod;
            dp[i][j]+=mod;
           // dp[i][j]=dp[i-1][j]+dp[i][j-1]+(i-1)*(j-1)%mod*dp[i-1][j-1]%mod;
            dp[i][j]%=mod;

        }
    }
    cout << dp[c][d];
}


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

int main () {
    string x, y;
    cin >> x >> y;
    y.pop_back();
    if (x == y) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

int main() {
  int N;
  int a[210];
  bool isGusu;
  int count; //2で割った回数
  
  //要素数の取得
  cin >> N;
  
  //初期化
  count = 0;
  isGusu = true;
  for (int i=0;i<N;i++) {
    cin >> a[i];
  }
  
  //処理開始
  while(isGusu) { //偶数のみの場合処理を続ける
    //走査
    for (int i=0;i<N;i++) {
      if (a[i]%2 == 1) {
        //奇数が存在した
        isGusu = false;
        break;
      }
    }
    
    //偶数のみか
    if (isGusu == true) {
      //すべての数を2で割る
      for (int i=0;i<N;i++) {
        a[i] /= 2;
      }
      //カウントを追加
      count++;
    }
    
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <sstream>
using namespace std;

bool cmp(pair<string, int> x, pair<string, int> y) {
    return x.second!=y.second ? x.second>y.second : x.first < y.first;
}

int main() {
    for(int N; cin >> N, N; ) {
        map<char, map<string, int> > dict;
        cin.ignore();
        for(int i = 0; i < N; i++) {
            string s; getline(cin, s);
            istringstream iss(s);
            for(string t; iss >> t; dict[t[0]][t]++);
        }
        char c; cin >> c;
        vector<pair<string, int> > res(dict[c].begin(), dict[c].end());
        sort(res.begin(), res.end(), cmp);
        if(res.empty()) {
            cout << "NA" << endl;
        }
        else {
            for(int i = 0, end = min<int>(res.size(), 5); i < end; i++) {
                cout << res[i].first << " \n"[i == end - 1];
            }
        }
    }
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
bool is_ok(ll x, ll y){
    if(x == y) return true;
    else return false;
}
int main(){

    string s;
    cin >> s;
    int q;
    cin >> q;

    bool flg_rev = false;

    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        if(t == 1){
            if(s.size() != 1){
                if(flg_rev) flg_rev = false;
                else flg_rev = true;
            }
        }
        else if(t == 2){
            int f;
            cin >> f;
            string c;
            cin >> c;
            if(!flg_rev){
                if(f == 1) s.insert(0, c);
                else if(f == 2) s.append(c);
            }
            else{
                if(f == 1) s.append(c);
                else if(f == 2) s.insert(0, c);
            }
        }
    }
    
    if(flg_rev){
        reverse(s.begin(), s.end());
    }
    
    cout << s << endl;
}


Measured memory_bytes: 900
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstring>
#include<algorithm>
#define RG register
#define ll long long
#define N 210000
#define MOD 1000000007
using namespace std;

inline ll read(){
    ll x=0,o=1;
    char ch=getchar();
    while((ch>'9'||ch<'0')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}

int n,len,Min; char s[N];
struct mona { int x,y; } ans[N];

int main(){
	scanf("%s",s+1),n=strlen(s+1); if(s[1]=='0'||s[n]=='1') return puts("-1"),0;
	for(RG int i=1;i<n;++i) if(i!=n-i&&s[i]!=s[n-i]) return puts("-1"),0;
	int lst=1,tot=1; //ans[++len]=(mona) { 1,2 };
	for(RG int i=1;i<n;++i){
		if(s[i]=='1'){
//			if(s[n-i+1]=='0') return puts("-1"),0;
			ans[++len]=(mona) { ++tot,lst },lst=tot;
		}	else ans[++len]=(mona) { ++tot,lst };
	}   for(RG int i=1;i<=len;++i) printf("%d %d\n",ans[i].x,ans[i].y);
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[4];
    cin>>s;
    if(s[0]=='A'&&s[1]=='B'&&s[2]=='A')
    {
        printf("Yes");
    }
    else if(s[0]=='A'&&s[1]=='B'&&s[2]=='B')
    {
        printf("Yes");
    }
    else if(s[0]=='B'&&s[1]=='A'&&s[2]=='A')
    {
        printf("Yes");
    }
    else if(s[0]=='A'&&s[1]=='A'&&s[2]=='B')
    {
        printf("Yes");
    }

    else if(s[0]=='B'&&s[1]=='B'&&s[2]=='A')
    {
        printf("Yes");
    }
    else if(s[0]=='B'&&s[1]=='A'&&s[2]=='B')
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    cout<<endl;
    return 0;
}


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

using namespace std;
typedef pair<double, double> P;
static const double eps = 1.0e-9;

double Helon(P p1, P p2, P p3)
{
	double a, b, c;
	a = sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
	b = sqrt((p2.first - p3.first) * (p2.first - p3.first) + (p2.second - p3.second) * (p2.second - p3.second));
	c = sqrt((p3.first - p1.first) * (p3.first - p1.first) + (p3.second - p1.second) * (p3.second - p1.second));
	double s = (a + b + c) / 2;
	return(sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve()
{
	P p[3];
	P pp;
	while(cin >> p[0].first)
	{
		cin >> p[0].second;
		for(int i = 1; i < 3; ++i)
		{
			cin >> p[i].first >> p[i].second;
		}
		cin >> pp.first >> pp.second;
		double sum1 = 0;
		sum1 = Helon(p[0], p[1], p[2]);
		double sum = 0;
		sum += Helon(p[0], p[1], pp);
		sum += Helon(p[1], p[2], pp);
		sum += Helon(p[2], p[0], pp);
		if(fabs(sum1 - sum) < eps)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

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

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

int main() {
    ios::sync_with_stdio(false);
    long long n;
    cin >> n;
    for (long long h = 3500; h >= 1; h--) {
        long long a = 4 * h - n, b = n * h;
        if (a > 0) {
            for (long long i = 3500; i >= 1; i--) {
                long long c = a * i - b, d = b * i;
                if (c > 0) {
                    if (d % c == 0) {
                        cout << h << " " << i << " " << d / c;
                        return 0;
                    }
                } else {
                    break;
                }
            }
        } else {
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int cut[20000001];
   int n,k;
   cin >> n >>k;
   for(int i=0;i<n;i++){
       int a;
       cin >> a;
       cut[a-1]++;
    }
    sort(cut,cut+n);
    int ans=0;
    for(int i=0;i<n-k;i++){
        ans += cut[i];

    }
    cout << ans << endl;
}

Measured memory_bytes: 2944
import scala.io.StdIn.readLong
object Main {
    def main(args: Array[String]): Unit = {
        val len = readLong
        val list = (1l to len).toList.map(x => readLong)
        println(maximumProfit(list)._2)
    }
    
    def maximumProfit(list: List[Long]): (Long, Long) = {
        def go(list: List[Long], min: Long, maxDiff: Long): (Long, Long) = list match {
            case x :: xs if x < min && (x - min) > maxDiff => go(xs, x, x - min)
            case x :: xs if x < min => go(xs, x, maxDiff)
            case x :: xs if (x - min) > maxDiff => go(xs, min, x - min)
            case x :: xs => go(xs, min, maxDiff)
            case _ => (min, maxDiff)
        }
        list match {
            case x :: xs => xs match { 
                case y :: ys => go(xs, x, y - x)
                case _ => (0l, 0l)
            }
            case _ => (0l, 0l)
        }
    }
}


Measured memory_bytes: 87804
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Combination
{
	vector<ll> fact, inv, invFact;
	int MAX_FACT;
	ll MOD;
	Combination(int n, ll mod) : fact(n + 1), inv(n + 1), invFact(n + 1)
	{
		MAX_FACT = n + 1;
		MOD = mod;
		fact[0] = 1;
		fact[1] = 1;
		invFact[0] = 1;
		invFact[1] = 1;
		inv[1] = 1;
		for (auto i = 2; i < MAX_FACT; ++i)
		{
			fact[i] = fact[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			invFact[i] = invFact[i - 1] * inv[i] % MOD;
		}
	}

	unsigned long long calcCombination(int n, int k)
	{
		if (n < k)
		{
			return 0;
		}
		if ((n < 0) || (k < 0))
		{
			return 0;
		}

		return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
	}
};


int main()
{
	int X, Y;
	cin >> X >> Y;

	auto ans = 0ll;
	auto mod = (ll)1e9 + 7;
	auto a = 2 * X - Y;
	auto b = 2 * Y - X;
	if ((X + Y) % 3 == 0
		&& a >= 0
		&& b >= 0)
	{
		a /= 3;
		b /= 3;
		Combination c(a + b, mod);
		ans = c.calcCombination(a + b, a);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
import javax.swing.DefaultBoundedRangeModel

import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val nodes = Array.fill(n){Nil: List[Int]}
  for (_ <- 0 until m) {
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt - 1)
    nodes(u) ::= v
  }
  val Array(s, t) = readLine.trim.split(' ').map(_.toInt - 1)
  val reachable = Array.fill(n){Array.fill(3){-3}}
  reachable(s)(0) = 0
  mark(List(s))
  println(
    reachable(t)(0) / 3
  )
  @tailrec
  def mark(current: List[Int], count: Int = 1): Unit = {
    current match {
      case Nil => ()
      case _ =>
        var next = Nil: List[Int]
        for (c <- current) {
          for (n <- nodes(c) if reachable(n)(count % 3) == -3) {
            reachable(n)(count % 3) = count
            next ::= n
          }
        }
        mark(next, count + 1)
    }
  }
}

Measured memory_bytes: 78520
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        mut pp: [usize; n],
    }

    pp.sort();

    let ans = pp.iter().copied().take(k).sum::<usize>();

    println!("{}", ans);
}

Measured memory_bytes: 2132
import sys
import collections
from functools import lru_cache

xy = []
d = collections.defaultdict(list)
@lru_cache(maxsize=None)
def alg_memoization_recursion(f):
    mt = 0
    for v in d[f]:
        mt = max(mt, alg_memoization_recursion(v) + 1)
    return mt


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    sys.setrecursionlimit(10 ** 5 + 1)
    n, m = list(map(int, readline().split()))
    for i in range(m):
        x, y = list(map(int, readline().split()))
        d[x-1] += [y-1]
    mt = 0
    for i in range(n):
        mt = max(mt, alg_memoization_recursion(i))
    print(mt)


if __name__ == '__main__':
    solve()


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

vector<int> l;
string avl = "0123456789";
int n;

void f(string str){
  if(stoi(str)>=n)l.push_back(stoi(str));
  else for(auto ch:avl)f(str+to_string(ch-'0'));
}
int main(){
  int k,c;
  cin>>n>>k;
  for(int i=0;i<k;++i)avl.erase(find(avl.begin(),avl.end(),(cin>>c,c+'0')));
  for(auto ch:avl)if(ch-'0')f(to_string(ch-'0'));
  sort(l.begin(),l.end());
  cout<<l[0];
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define rev(v) 	v.rbegin(), v.rend()
#define all(v) v.begin(), v.end()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << endl;
}

int main() {
	int c[3][3];
	bool flag = true;
	For(i, 3)For(j, 3)cin >> c[i][j];
	rep(2) {
		if (!(c[0][i] - c[0][i + 1] == c[1][i] - c[1][i + 1] && c[1][i] - c[1][i + 1] == c[2][i] - c[2][i + 1]))
			flag = false;
		if (!(c[i][0] - c[i + 1][0] == c[i][1] - c[i + 1][1] && c[i][1] - c[i + 1][1] == c[i][2] - c[i + 1][2]))
			flag = false;
	}
	flag ? say("Yes") : say("No");
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N, i, n = 0, ans = 0;
    scanf("%d", &N);
    int H[N];
    for (i = 0; i < N; i++) {
        scanf("%d", &H[i]);
        if (H[i] >= n) {
            n = H[i];
            ans++;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int h, w;
    cin >> h >> w;
    char s[2001][2001];
    Int l[2001][2001];
    Int r[2001][2001];
    Int u[2001][2001];
    Int d[2001][2001];
    for(Int i=0; i<h; i++){
        cin >> s[i];
    }

    // left
    for(Int i=0; i<h; i++){
        for(Int j=0; j<w; j++){
            if(j==0){
                l[i][j] = 0;
                continue;
            }
            if(s[i][j]=='#'){
                l[i][j] = 0;
                continue;
            }
            if(s[i][j-1]=='#'){
                l[i][j] = 0;
            }else{
                l[i][j] = l[i][j-1] + 1;
            }
        }
    }

    // right
    for(Int i=0; i<h; i++){
        for(Int j=w-1; j>=0; j--){
            if(j==w-1){
                r[i][j] = 0;
                continue;
            }
            if(s[i][j]=='#'){
                r[i][j] = 0;
                continue;
            }
            if(s[i][j+1]=='#'){
                r[i][j] = 0;
            }else{
                r[i][j] = r[i][j+1] + 1;
            }
        }
    }

    // up
    for(Int i=0; i<h; i++){
        for(Int j=0; j<w; j++){
            if(i==0){
                u[i][j] = 0;
                continue;
            }
            if(s[i][j]=='#'){
                u[i][j] = 0;
                continue;
            }
            if(s[i-1][j]=='#'){
                u[i][j]=0;
            }else{
                u[i][j] = u[i-1][j] + 1;
            }
        }
    }

    // down
    for(Int i=h-1; i>=0; i--){
        for(Int j=0; j<w; j++){
            if(i==h-1){
                d[i][j] = 0;
                continue;
            }
            if(s[i][j]=='#'){
                d[i][j] = 0;
                continue;
            }
            if(s[i+1][j]=='#'){
                d[i][j] = 0;
            }else{
                d[i][j] = d[i+1][j] + 1;
            }
        }
    }

    Int max = 0;
    for(Int i=0; i<h; i++){
        for(Int j=0; j<w; j++){
            tmpi = l[i][j] + r[i][j] + u[i][j] + d[i][j] + 1;
            max = tmpi > max ? tmpi : max;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 129280
#include<iostream>
#include<vector>
#include<string>
using namespace std;
 
int main(){
int a;
while(cin>>a,a){
vector<int>s(a+1);
for(int b=0;b<a+1;b++)cin>>s[b];
for(int c=0;c<a+1;c++){
vector<int>copy(a+1);
for(int d=0;d<a+1;d++)copy[d]=s[d];
for(int d=c;d<a;d++)copy[d]=copy[d+1];
copy.pop_back();
int f=copy[1]-copy[0];
for(int e=0;e<a-1;e++){
if(copy[e+1]-copy[e]!=f)break;
if(a-2==e){cout<<s[c]<<endl;goto l;}
}
}
l:;}
}

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

typedef long long LL;

const int N=2e5+10;

int n,m,a[N];
LL p[N],k[N];

void Init() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
}

void add(int l,int r) {
	k[l]++; k[r+1]--; p[r+1]-=r-l+1; 
}

void Solve() {
	LL tot=0ll;
	for (int i=1;i<n;++i) {
		int l=a[i],r=a[i+1]; if (r<l) r+=m;
		tot+=r-l;
		add(l+2,r);
	}
	for (int i=1;i<=m*2;++i) k[i]+=k[i-1];
	for (int i=1;i<=m*2;++i) p[i]+=p[i-1]+k[i];
	LL ans=1e18;
	for (int i=1;i<=m;++i) ans=std::min(ans,tot-p[i]-p[i+m]);
	printf("%lld\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int X, Y, Z, K;  
	cin >> X >> Y >> Z >> K;
	long long int A[1010] = {}; 
	long long int B[1010] = {}; 
	long long int C[1010] = {}; 
	for(int i = 0; i < X; i++){
		cin >> A[i]; 
	}
	for(int i = 0; i < Y; i++){
		cin >> B[i]; 
	}
	for(int i = 0; i < Z; i++){
		cin >> C[i]; 
	}
	sort(A, A+X, greater<long long int>()); 
	sort(B, B+Y, greater<long long int>()); 
	sort(C, C+Z, greater<long long int>());
	vector<long long int> ans = {}; 
	bool utikiri = false; 
	for(int i = 0; i < X; i++){
		for(int j = 0; j < Y; j++){
			for(int k = 0; k < Z; k++){
				ans.push_back(A[i]+B[j]+C[k]); 
				if(i * j * k > K){
					utikiri = true; break; 
				}
			}
		}
	}
	sort(ans.begin(), ans.end(), greater<long long int>()); 
	for(int i = 0; i < K; i++){
		cout << ans[i] << endl; 
	}
}

Measured memory_bytes: 35044
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = Slist();
            if (Ai.Contains(9)) { Ai.Remove(6); }
            if (Ai.Contains(5)) { Ai.Remove(3); Ai.Remove(2); }
            if (Ai.Contains(3)) { Ai.Remove(2); }

            var pair = new Dictionary<long, long>()
            {
                { 1, 2 }, { 2, 5 }, { 3, 5 }, { 4, 4 }, { 5, 5 },
                { 6, 6 }, { 7, 3 }, { 8, 7 }, { 9, 6 }
            };
            var AiPair = new List<(long n, long c)>();
            foreach (var a in Ai)
                AiPair.Add((a, pair[a]));
            var min = AiPair.First(a => a.c == AiPair.Min(c => c.c));
            AiPair = AiPair.Where(a => a.c % min.c != 0).Select(a => (a.n, a.c - min.c)).ToList();
            var left = AiPair.Where(a => a.n > min.n).OrderByDescending(a => a.n).ToList();
            var right = AiPair.Where(a => a.n < min.n).OrderByDescending(a => a.c).ToList();
            var keta = N / min.c;
            for (keta = N / min.c; 0 < keta; --keta)
            {
                used = new long[AiPair.Count];
                if (dfs(N - keta * min.c, 0, left.Concat(right).ToList())) break;
            }
            var ans = string.Empty;
            for (var i = 0; i < left.Count; ++i)
                ans += new string(left[i].n.ToString()[0], (int)used[i]);
            ans += new string(min.n.ToString()[0], (int)(keta - used.Sum()));
            for (var i = 0; i < right.Count; ++i)
                ans += new string(right[i].n.ToString()[0], (int)used[left.Count + i]);
            WriteLine(ans);
        }
        static long[] used;
        static bool dfs(long rem, int i, List<(long n, long c)> pair)
        {
            if (rem == 0) return true;
            if (rem < 0 || pair.Count <= i) return false;
            var cst = pair[i].c;

            for (var k = rem / cst; 0 <= k; --k)
            {
                if (dfs(rem - k * cst, i + 1, pair))
                {
                    used[i] = k;
                    return true;
                }
            }
            return false;
        }
    }
}

Measured memory_bytes: 28652