akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second

struct BIT{
	int siz;
	ll s[(1<<17)+1];
	void init(){
		siz = 1<<17;
		for(int i = 1 ; i <= siz ; i ++){
			s[i] = 0;
		}
	}
	void add(int k,ll x){
		while(k > 0){
			s[k] += x;
			k -= k&-k;
		}
	}
	void add_range(int a,int b,ll x){
		add(b,x);
		if(a != 1)add(a-1,-x);
	}
	ll sum(int k){
		ll ret = 0;
		while(k <= siz){
			ret += s[k];
			k += k&-k;
		}
		return ret;
	}
}A,B;

int main(){
	static int n,m;
	static ll a[100010];
	scanf("%d%d",&n,&m);
	for(int i = 1 ; i <= n ; i ++){
		scanf("%lld",&a[i]);
	}
	
	A.init();
	B.init();
	for(int i = 1 ; i+1 <= n ; i ++){
		if(a[i] < a[i+1]){
			B.add_range(1,a[i],a[i+1]-a[i]);
			A.add_range(a[i]+1,a[i+1],-1);
			B.add_range(a[i]+1,a[i+1],a[i+1]+1);
			B.add_range(a[i+1]+1,m,a[i+1]-a[i]);
		}
		else {
			A.add_range(1,a[i+1],-1);
			B.add_range(1,a[i+1],a[i+1]+1);
			B.add_range(a[i+1]+1,a[i],m+a[i+1]-a[i]);
			A.add_range(a[i]+1,m,-1);
			B.add_range(a[i]+1,m,m+a[i+1]+1);
		}
	}
	
	ll ret = 1000000000000000000;
	for(int i = 1 ; i <= m ; i ++){
		ret = min( ret , A.sum(i)*i + B.sum(i) );
	}
	cout << ret << endl;
}



Measured memory_bytes: 3072
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        int map[][] = new int[h + 2][w + 2];
        Queue<Pos> queue = new ArrayDeque<Pos>();
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            for (int j = 0; j < w; j++) {
                char c = s.charAt(j);
                if (c == '#') {
                    queue.add(new Pos(i + 1, j + 1));
                    map[i + 1][j + 1] = 1;
                }
            }
        }
        Arrays.fill(map[0], -1);
        Arrays.fill(map[h + 1], -1);
        for (int i = 0; i < h + 1; i++) {
            map[i][0] = -1;
            map[i][w + 1] = -1;
        }
        int max = 1;
        while (!queue.isEmpty()) {
            Pos p = queue.poll();
            int dx[] = { 0, 1, 0, -1 };
            int dy[] = { -1, 0, 1, 0 };
            for (int i = 0; i < 4; i++) {
                int ni = p.i + dx[i];
                int nj = p.j + dy[i];
                if (map[ni][nj] == 0) {
                    map[ni][nj] = map[p.i][p.j] + 1;
                    max = Math.max(max, map[ni][nj]);
                    queue.add((new Pos(ni, nj)));
                }
            }
        }

        System.out.println(max - 1);

        sc.close();
    }
}

class Pos {
    int i, j;

    Pos(int i, int j) {
        this.i = i;
        this.j = j;
    }
}


Measured memory_bytes: 100748
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    int sum = 0;
    int max_p = 0;
    for(int i = 0; i < n; i++){
        int p; cin >> p;
        max_p = max(p,max_p);
        sum += p;
    }
    cout << sum - max_p/2 <<endl;
}

Measured memory_bytes: 256
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
	static int[][] d;
	static int ans = Integer.MAX_VALUE;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int r = sc.nextInt();
		int[] t = new int[r];
		for (int i = 0; i < r; i++) {
			t[i] = sc.nextInt() - 1;
		}
		d = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j) {
					d[i][j] = 1000000000;
				}
			}
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			int c = sc.nextInt();
			d[a][b] = c;
			d[b][a] = c;
		}
		sc.close();

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		permutation(t, new LinkedHashSet<>());
		System.out.println(ans);
	}

	static void permutation(int[] target, LinkedHashSet<Integer> set) {
		if (set.size() == target.length) {
			Integer[] arr = set.toArray(new Integer[0]);
			int sum = 0;
			for (int i = 1; i < arr.length; i++) {
				sum += d[target[arr[i - 1]]][target[arr[i]]];
			}
			ans = Math.min(ans, sum);
			return;
		}

		for (int i = 0; i < target.length; i++) {
			if (!set.contains(i)) {
				set.add(i);
				permutation(target, set);
				set.remove(i);
			}
		}
	}
}


Measured memory_bytes: 45380
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        double[][] xy=new double[8][2];
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        final int X=0,Y=1;
        double gt=0;
        for(int i=0;i<n;i++){
            xy[i][X]=sc.nextDouble();
            xy[i][Y]=sc.nextDouble();
        }
        sc.close();
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                gt+=Math.sqrt(Math.pow(xy[i][X]-xy[j][X],2)+Math.pow(xy[i][Y]-xy[j][Y],2));
            }
        }
        System.out.println(gt*2/n);
    }
}

Measured memory_bytes: 25172
# N, A, B
num, greenNum, redNum = map(lambda x: int(x), input().split(' '))

numSet = num // (greenNum+redNum)
remain = num % (greenNum+redNum)
numRest = remain if (remain < greenNum) else greenNum

totalGreen = numSet * greenNum + numRest

print(totalGreen)


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.size()) {
        s[i] = s[i] + n;
        if(s[i] > 'Z') {
            s[i] = s[i] - 26;
        }
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#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;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

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

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

int main() {
  fast();
  cin >> n;
  set<string> st;
  char curr = ' ';
  FOR(i, 0, n) {
    string s;
    cin >> s;
    if (st.find(s) != st.end()) {
      cout << "No";
      return 0;
    }
    if (curr != ' ' and s[0] != curr) {
      cout << "No";
      return 0;
    }
    curr = s[s.length() - 1];
    st.ins(s);
  }
  cout << "Yes";
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
//using vec  = vector<pair<int, int>>;
//using vvec = vector<vec>;

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：
int fct(int m, int k) {
	int ft = 1;
	rep(i, k) ft *= m;
	return(ft);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int> A(N), ans(N);
	rep(i, N) {
		cin >> A.at(i);
	}
	
	rep(i, N) {
		int tp;
		tp = A.at(i) - 1;
		ans.at(tp) = i + 1;
	}

	rep(i, N) {
		cout << ans.at(i);
		if(i != N-1) cout << ' ';
		else cout << endl;
	}
	return 0;
}
// std::string str;
// str = std::to_string(int i);
// bitset<3> s(N);


Measured memory_bytes: 2432
#include<iostream>
using namespace std;
int N,M;
int a[2<<17],b[2<<17];
main()
{
  cin>>N>>M;
  for(int i=0;i<M;i++)
  {
    int u,v;cin>>u>>v;
    if(u==1)a[v]++;
    if(v==N)b[u]++;
  }
  int cnt=0;
  for(int i=1;i<=N;i++)cnt+=a[i]&&b[i];
  cout<<(cnt?"":"IM")<<"POSSIBLE"<<endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

ll N, M;

ll f(int x){
    ll res = 0;
    while(x % 2 == 0){
        res++;
        x /= 2;
    }
    return res;
}

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

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

int main()
{
    cin >> N >> M;
    int a[N];
    rep(i,N){
        int ai; cin >> ai;
        if(ai % 2 == 1){
            cout << 0 << endl;
            return 0;
        }
        ai /= 2;
        a[i] = ai;
    }
    int t = f(a[0]);
    rep(i,N){
        if(f(a[i]) != t){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    M >>= t;
    ll lc = 1;
    rep(i,N){
        lc = lcm(lc, a[i]);
        if(lc > M){
            cout << 0 << endl;
            return 0;
        }
    }
    // cout << lc << endl;
    ll m_lc = M / lc;
    if(m_lc % 2 == 0){
        cout << m_lc / 2 << endl;
    }else{
        cout << (m_lc+1)/2 << endl;
    }

}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1003;
const int H = 10004;

int dp[N][H];
int p[N], c[N];
int n;

int solve(int i, int h){
    if(i == n and h > 0) return INF;
    if(h <= 0) return 0;

    int& ret = dp[i][h];
    if(ret) return ret;

    return ret = min(solve(i + 1, h), c[i] + solve(i, h - p[i]));
}

int main(){
    fcin;
    int h;
    cin >> h >> n;

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

    cout << solve(0, h) << endl;
    return 0;
}



Measured memory_bytes: 39680
#include <stdio.h>
#include <limits.h>

void matrixChainOrder(int *,int);
int min(int,int);

  int p[100];
  int m[100][100];
int main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
      scanf("%d%d",&p[i-1],&p[i]);
  matrixChainOrder(p,n);
  return 0;
}

void matrixChainOrder(int *p,int n){
  int i,j,k,l,q;
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=min(m[i][j],q);
      }
    }
  }
  printf("%d\n",m[1][n]);
}

int min(int a,int b){
  if(a<b) return a;
  else return b;
}



Measured memory_bytes: 2052
#include<string>
#include<vector>
#include<cctype>
#include<cmath>
#include<iostream>
#include<map>
using namespace std;

double expectation(double i){
    double sum = i + i * (i - 1) / 2;
    return sum / i;
}

int main(){
    cout.setf(ios_base::showpoint);cout.precision(10);
    int N, t;
    vector<double> vi;
    double rs = 0;
    cin >> N >> t;
    double tmp;
    int cp = N;
    while(cp--){
        cin >> tmp;
        vi.push_back(expectation(tmp));
    }
    cp = t;
    int i = 0;
    auto p2 = vi.begin();
    while(cp--){
        rs += vi[i++];
        p2++;
    }
    double max = rs;
    
    for (auto p1 = vi.begin(),end = vi.end(); p2 != end; p2++, p1++)
    {
        rs += *p2;
        rs -= *p1;
        if(rs>max)
            max = rs;
    }


    cout << max << endl;

    return 0;
}

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

const long long C = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7;

long long power(int n, int r) {
  long long ret = 1;
  while (n > 0) {
    ret *= r;
    ret %= C;
    n--;
  }
  return ret;
}

int main() {
  long long N, ans {1};
  cin >> N;

  ans = power(N, 10);
  if (ans < 0) ans += C;
  ans -= power(N, 9);
  if (ans < 0) ans += C;
  ans -= power(N, 9);
  if (ans < 0) ans += C;
  ans += power(N, 8);
  ans %= C;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3196
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

void solve()
{
    ll k; cin>>k;
    queue<string> q;
    string ans = "";
    for(char i='1'; i<='9'; i++)
    {
        string x = "";
        x+=i;
        q.push(x);
    }
    while(k)
    {
        ans = q.front();
        q.pop();
        for(char i = '0'; i<='9'; i++)
        {
            if(abs(ans.back()-i)<=1) q.push(ans+i);
        }
        k--;
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(100000);
  rep(i,1,123) {
    rep(j,1,123) {
      rep(k,1,123) {
        a[i*i+j*j+k*k+i*j+i*k+j*k]++;
      }
    }
  }
  rep(i,1,n+1) {
    cout << a[i] << '\n';
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4044
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin >>a >>b>>c>>d;
  int sum=0;
  if(a>=b) sum+=b;
  else sum += a;
  if(c>=d) sum+=d;
  else sum+=c;
  cout <<sum<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,x,y,z,w;
	int a,b,c,d,e,f,g,h;
	
	while(cin>>n&&n) {
		for(i=0;i<n;i++) {
			cin>>a>>b>>c>>d>>e>>f>>g>>h;
			x=(a*e)+(-1*((b*f)+(c*g)+(d*h)));
			y=(a*f)+(c*h)+(-1*(g*d))+(e*b);
			z=(a*g)+(c*e)+(-1*(b*h))+(f*d);
			w=(a*h)+(d*e)+(b*g)+(-1*(c*f));
			printf("%d %d %d %d\n",x,y,z,w);
		}
		
	}
}
	

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
   string A,s,C;
   cin>>A>>s>>C;
   cout<<"A"<<s[0]<<"C"<<endl;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

using mint = modint998244353;
struct S {
    mint a;
    ll size;
};
S op(S a, S b){
    return S{a.a + b.a, a.size + b.size};
}

S e(){return {0, 0};}

struct F {
    mint a, b;
};
S mapping(F f, S x){
    return S{f.a * x.a + f.b * x.size, x.size};
}

F composition(F f, F g){
    return F{f.a * g.a, g.b * f.a + f.b};
}

F id(){return F{1, 0};};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,q; cin >> n >> q;
    vector<S> a(n);
    for(int i = 0; i < n; i++){
        ll t; cin >> t;
        a[i] = S{t, 1};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> lseg(a);
    rep(i,0,q){
        ll t; cin >> t;
        if(t == 0){
            ll l,r; cin >> l >> r;
            ll b,c; cin >> b >> c;
            lseg.apply(l, r, F{b, c});
        }
        else{
            ll l,r; cin >> l >> r;
            cout << lseg.prod(l, r).a.val() << "\n";
        }
    }
}

Measured memory_bytes: 31492
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod = 1000000007;

int go( int sum, vector<int>& coins, vector<int>& dp) {

	if (sum == 0) return 1;

	if (sum < 0) return 0;

	if (dp[sum] != -1) return dp[sum];

	int res = 0;

	for (int i = 0; i < coins.size(); i++) {
		res = (res + go( sum - coins[i], coins, dp)) % mod;

	}
	return  dp[sum] = res;
}





int main()
{
	abc();

	int s;
	cin >> s;
	vector<int> v;
	vector<int> dp(s + 1, -1);
	for (int i = 3; i <= s; i++) {

		v.push_back(i);

	}

	cout << go( s, v, dp);









}










Measured memory_bytes: 3700
#include<stdio.h>
int main(void){
  int n,i,j,tmp=0,cnt;
  scanf("%d",&n);
  int moti[n];
  for(i=0;i<n;i++){
    scanf("%d",&moti[i]);
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(moti[i]<moti[j]){
        tmp=moti[i];
        moti[i]=moti[j];
        moti[j]=tmp;
      }
    }
  }
  for(cnt=0,i=0;i<n;i++,cnt++){
    if(moti[i]==moti[i-1]){
      cnt--;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
#include <iomanip>
using namespace std;
int n,p,t=0,s[50];
int main() {
	cin >> n >> p;
	for (size_t i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	sort(s, s+n);
	for (size_t j = 0; j < p; j++)
	{
		t += s[n-1-j];
	}
	cout << t << endl;
	return 0;
}


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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int n;cin>>n;
  int res=0;
  for(int i=1;i<=1000050;i++){
    if(i>=n)break;
    int buf=n;
    buf-=i;
    if(buf%i==0&&buf!=0){
      int hoge=buf/i;
      if(n%hoge==0)continue;
      if(i>=hoge)continue;
      res+=buf/i;
      //printf("i=%lld buf/i=%lld\n",i,buf/i);
      //cout<<"res="<<res<<endl;
    }
  }
  cout<<res<<endl;
  return 0;
}

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

dp=[0]*n

ans=0

if n==2:
  ans=abs(h[0]-h[1])
else:
  dp[0]=0
  dp[1]=abs(h[1]-h[0])

  for i in range(n-2):
    dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i+1]))
  ans=dp[n-1]

print(ans)

Measured memory_bytes: 13908
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,d= map(int, sys.stdin.readline().split(' '))
    dis = 2*d+1
    val = n//dis
    if val*dis <n:
        val+=1
    print(val)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    string s;
    ll k;
    cin >> s >> k;
    vector<string> x;
    for (ll i=0;i<s.size();i++){
        string p="";
        for (ll j=i;j<s.size() and j-i<5;j++){
            p=p+s[j];
            x.push_back(p);
        }
    }
    sort(x.begin(),x.end());
    string p;
    ll c=0;
    if (k==1){
        cout << x[0] << endl;
        return 0;
    }
    for (ll i=1;i<s.size()*k;i++){
        if (x[i]==x[i-1])c++;
        if (i-c==k-1){
            p=x[i];
            break;
        }
    }
    cout << p << endl;
    return 0;
}




Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = intArray[0];
            int K = intArray[1];
            int[] shintyou = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int cnt = 0;
            for(int i = 0; i < N; i++)
            {
                if(K <= shintyou[i])
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    } 
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 35248
import sys

X = sys.stdin.readline().strip()
lx = len(X)

stack = []
pop_n = 0
for c in X:
    if c == "S":
        stack.append(c)
    elif c == "T" and 0 < len(stack):
        stack.pop()
        pop_n += 1

print(lx - 2 * pop_n)

Measured memory_bytes: 82104
# -*- coding: utf-8 -*-

N=int(input())
p=[int(i) for i in input().split()]
ch=[]

def judge():
    flag = 1
    for j in range(N):
        if p[j] == j+1:
            continue
        else:
            ch.append(j)
            flag = 0
    return flag,ch

flag,ch = judge()

if flag == 0:
    temp = p[ch[0]]
    p[ch[0]] = p[ch[1]]
    p[ch[1]] = temp

flag,ch = judge()

if flag== 1:
    print('YES')
else:
    print('NO')

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

int main() {
	queue<pair<string, int> > que;
	pair<string, int> tmp;
	int n; cin >> n;
	int q; cin >> q;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> tmp.first >> tmp.second;
		que.push(tmp);
	}
	while (!(que.empty())) {
		tmp = que.front();
		que.pop();
		int num = tmp.second;
		if (num > q) {
			num -= q;
			cnt += q;
			tmp.second = num;
			que.push(tmp);
		}
		else {
			cnt += num;
			cout << tmp.first << " " << cnt << endl;
		}
	}
}


Measured memory_bytes: 6328
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int dp[3010][3010];
int back[3010][3010];

int main(){
  string s, t;

  cin >> s >> t;

  for(int i=0;i<s.size();i++){
    for(int j=0;j<t.size();j++){
      if(s[i] == t[j] && dp[i+1][j+1] < dp[i][j]+1) {
        dp[i+1][j+1] = dp[i][j]+1;
        back[i+1][j+1] = 1;
      }
      if(dp[i+1][j] < dp[i][j]) {
        dp[i+1][j] = dp[i][j];
        back[i+1][j] = 2;
      }
      if(dp[i][j+1] < dp[i][j]) {
        dp[i][j+1] = dp[i][j];
        back[i][j+1] = 3;
      }
    }
  }

  string ans = "";

  int a = s.size(), b = t.size();

  debug(dp[a][b]);

  for(int i=0;i<=s.size();i++){
    for(int j=0;j<=t.size();j++){
      if (dp[a][b] < dp[i][j]){
        a = i; b = j;
      }
    }
  }

  while(dp[a][b]){
    if(back[a][b] == 1) {
      ans = s[a-1] + ans;
      a--; b--;
    }
    if (back[a][b] == 2) {
      a--;
    }
    if (back[a][b] == 3) {
      b--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70912
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))
bit = [0]*41
for i in range(n):
        for j in range(41):
                if a[i] & 1<<j:
                        bit[j] += 1
ans = 0
ima = 0
for i in range(40,-1,-1):
        if ima + (1<<i) > k:
                ans +=  bit[i]*(1<<i)
                continue
        if bit[i] < n/2:
                ans += (n-bit[i])*(1<<i)
                ima += 1<<i
        else:
                ans +=  bit[i]*(1<<i)
print(ans)

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

if(b>1){
while(a>b/2)a--;
s+=a;
b-=a*2;
}


s+=b/4;
cout<<s<<endl;
}

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

using namespace std;

const int md = 924844033;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

const int N = 2010;

int fact[N];
int res[N], new_res[N];
int can_right[N], can_left[N];
int f[N][N][2];
int cur[N];

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  int n, k;
  scanf("%d %d", &n, &k);
  int total = 0;
  res[0] = 1;
  for (int r = 0; r < 2 * k && r < n; r++) {
    int m = 0;
    for (int i = r; i < n; i += 2 * k) {
      can_left[m] = (i - k >= 0);
      can_right[m] = (i + k < n);
      m++;
    }
    for (int i = 0; i <= m; i++) {
      for (int j = 0; j <= m; j++) {
        for (int t = 0; t < 2; t++) {
          f[i][j][t] = 0;
        }
      }
    }
    f[0][0][0] = 1;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j <= i; j++) {
        for (int t = 0; t < 2; t++) {
          int ft = f[i][j][t];
          if (ft == 0) {
            continue;
          }
          add(f[i + 1][j][0], ft);
          if (can_left[i] && t == 0) {
            add(f[i + 1][j + 1][0], ft);
          }
          if (can_right[i]) {
            add(f[i + 1][j + 1][1], ft);
          }
        }
      }
    }
    for (int j = 0; j <= m; j++) {
      cur[j] = (f[m][j][0] + f[m][j][1]) % md;
    }
    for (int i = 0; i <= total + m; i++) {
      new_res[i] = 0;
    }
    for (int i = total; i >= 0; i--) {
      for (int j = 0; j <= m; j++) {
        add(new_res[i + j], mul(res[i], cur[j]));
      }
    }
    total += m;
    for (int i = 0; i <= total; i++) {
      res[i] = new_res[i];
    }
  }
  int ans = 0;
  for (int i = 0; i <= total; i++) {
    int value = mul(res[i], fact[n - i]);
    add(ans, i % 2 == 0 ? value : (md - value));
  }
  printf("%d\n", ans);
  return 0;
}


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

double prob[610], expe[610], esum[610], mx[610];

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> v(N+1);
	for(int i=0; i<M; ++i){
		int s, t;
		cin >> s >> t;
		v[s].emplace_back(t);
	}
	prob[1]=1.0;
	for(int i=1; i<N; ++i){
		for(int j=0; j<v[i].size(); ++j){
			prob[v[i][j]] += prob[i]/v[i].size();
		}
	}
	for(int i=N-1; i>0; --i){
		for(int j=0; j<v[i].size(); ++j){
			esum[i] += expe[v[i][j]];
			mx[i]=max(mx[i], expe[v[i][j]]);
		}
		expe[i]=1.0+esum[i]/v[i].size();
	}
	double ans=0.0;
	for(int i=1; i<N; ++i){
		if(v[i].size()>1){
			ans=max(ans, prob[i]*(expe[i]-(esum[i]-mx[i])/(v[i].size()-1)-1.0));
		}
	}
	cout << setprecision(15) << expe[1]-ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)


char s[100001];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  int m = n>>1;

  int ans1 = n;
  for (int i = m; i > 0; --i) {
    if (s[i-1] != s[i]) {
      ans1 = n-i;
      break;
    }
  }

  int ans2 = n;
  for (int i = m+1; i < n; ++i) {
    if (s[i-1] != s[i]) {
      ans2 = i;
      break;
    }
  }

  printf("%d\n", min(ans1, ans2));
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
using namespace std;
#define lli long long int
int main()
{
    lli n, m, xi, r, d, i;
    cin>>r>>d>>xi;
    n=xi;
    for(i=1; i<=10; i++)
    {
        //n+=xi;
        xi=(r*n)-d;
        n=xi;
        cout<<xi<<endl;
        //n+=xi;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  string s;
  cin >> s;
  bool ans = true;
  for (i64 i = 0; i < s.size(); i++)
    if (i % 2 == 0 && s[i] == 'L')
      ans = false;
    else if (i % 2 == 1 && s[i] == 'R')
      ans = false;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

mod = N % 1000
if mod==0:
    exchange = 0
else:
    exchange = 1000-mod

print(exchange)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(n,-1);
  int z=0;
  vector<vector<int>> p;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a-=1;b-=1;
    if (c[a]==-1 && c[b]==-1){
      c[a]=z;
      c[b]=z;
      p.push_back(vector<int>(1,a));
      p[z].push_back(b);
      z++;
    }
    if (c[a]==-1 && c[b]!=-1){
      c[a]=c[b];
      p[c[b]].push_back(a);
    }
    if (c[a]!=-1 && c[b]==-1){
      c[b]=c[a];
      p[c[a]].push_back(b);
    }
    if (c[a]!=-1 && c[b]!=-1 && c[a]!=c[b]){
      int x=min(c[a],c[b]);
      int y=max(c[a],c[b]);
      rep(j,p[y].size()){
        p[x].push_back(p[y][j]);
        c[p[y][j]]=x;
      }
    }
  }
  int res=1;
  rep(i,p.size()){
    if (p[i].size()>res) res=p[i].size();
  }
  cout << res <<endl;
}


Measured memory_bytes: 12424
#include<stdio.h>
int main(void)
{
	int n,nbox[10000],temp,i,j,flg;
	scanf("%d",&n);
	while(n!=-1){
		temp=0;
		i=0;
		flg=0;
		while(n>=4){
			nbox[i]=n%4;
			n/=4;
			i++;
		}
		printf("%d",n);
		for(j=i;j>=0;j--){
			if(flg==0){
				flg=1;
			}
			else if(flg==1){
				printf("%d",nbox[j]);
			}
		}
		printf("\n");
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int N, i;
    cin >> N >> i;
    cout << N - i + 1 << endl;
    // system("pause");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
char a[110][110];
bool b[110], c[110];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)cin >> a[i][j];
	}
	for (int i = 0; i < n; i++) {
		bool f = false;
		for (int j = 0; j < m; j++) {
			if (a[i][j] == '#')f = true;
		}
		if (!f)b[i] = true;
	}
	for (int i = 0; i < m; i++) {
		bool f = false;
		for (int j = 0; j < n; j++) {
			if (a[j][i] == '#')f = true;
		}
		if (!f)c[i] = true;
	}
	for (int i = 0; i < n; i++) {
		if (b[i])continue;
		for (int j = 0; j < m; j++) {
			if (c[j])continue;
			cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

/*
bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    if (a == b) 
        return a; 
   
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
void dfs(int x,int y){
		if(x == n+1){
			int tmp = 0;
			FOR(i,0,k){
				if(tmp1[mortyy[i]]-tmp1[morty[i]] == mortyyy[i])tmp+=mortyyyy[i];
			}
			rick = max(rick,tmp);
			return ;
		}
		int i;
		for(i = y;i<=n1;i++){
			tmp1[x] = i;
			dfs(x+1,i);
		}
	}
*/

int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    if (a == b) 
        return a; 
   
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

//3111111111111111111111111111111




	void solve(){
		
		ini(n);
		vi morty;
		FOR(i,0,n){
			ini(x);
			morty.push_back(x);
		}
		vi ll;
		vi rr;
		int tmp = morty[0];
		FOR(i,0,n){
			tmp = __gcd(tmp,morty[i]);
			ll.push_back(tmp);
		}
		tmp  =morty[n-1];
		for(int i = n-1;i>=0;i--){
			tmp = __gcd(tmp,morty[i]);
			rr.push_back(tmp);
		}
		reverse(all(rr));
		//for(auto x:ll){cout<<x<<" ";}
		//	out();
		//for(auto x:rr){cout<<x<<" ";}
		//	out();
		int rick = 0;
		FOR(i,1,n-1){
			rick = max(rick,__gcd(ll[i-1],rr[i+1]));
		}
		rick = max(rick,rr[1]);
		rick = max(rick,ll[n-2]);
		out(rick);

	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

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

const double pi = acos(-1);
#define INF 999999999
int main ()
{
    long long all=0,cnt=0,n,max=-INF,min=INF;
    vector<int>h(10000);
    vector<int>w(10000);

    for(int i=0;i<10000;i++){
        cin >> h.at(i) >> w.at(i);
        
        if(h.at(i)==0 && w.at(i)==0) break;
        cnt++;
    }

    for(int i=0;i<cnt;i++){
        for(int j=0;j<h.at(i);j++){
            for(int k=0;k<w.at(i);k++){
                if((k+j)%2==0) cout << '#';
                
                else cout << '.';
            }
            cout << endl;
        }

        cout << endl;
    }

    

    
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int a,b,c,i,j,n,s;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
     for (j=0;j<=b;j++)
      if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) ++s;
    printf("%d\n",s);
    return 0;
}

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

int sosudiagnosis(int);

int main()
{
  int n; //入力できる個数
  int s; //数
  int l=0; //ループの回数
  int count=0;//素数の数

  scanf("%d",&n);
  while(l < n){
    l++;
    scanf("%d",&s);

    if(sosudiagnosis(s)==1) count++;
  }
  printf("%d\n",count);
  return 0;
}

int sosudiagnosis(int s)
{
  int i;
  if(s == 2) return 1;

  if(s < 2 || s%2==0) return 0;

  for(i = 3;i <= sqrt(s);i += 2){//平方根にして数を小さくする
    if(s%i==0) return 0;
  }
  return 1;
}

Measured memory_bytes: 596
from collections import deque

# グラフに辺を追加する
def addEdge(adjL, vFr, vTo, cap):
    adjL[vFr].append([vTo, cap, len(adjL[vTo])])
    adjL[vTo].append([vFr, 0, len(adjL[vFr]) - 1]) # 逆辺


# Dinic法（最大フローを求める）
def Dinic(adjL, vSt, vEn):

    # 始点からの最短距離を、BFSで求める
    def BFS(vSt):
        dist[vSt] = 0
        Q = deque([vSt])
        while Q:
            vNow = Q.popleft()

            for i, (v2, cap, iRev) in enumerate(adjL[vNow]):
                if dist[v2] == -1 and cap > 0:
                    # 未探索の頂点への辺の容量に空きがある場合、探索する
                    dist[v2] = dist[vNow] + 1
                    Q.append(v2)


    # 残余グラフの始点から終点までの経路（増加パス）を、DFSで探索する
    def DFS(vNow, vEn, fNow):
        if vNow == vEn:
            # 終点に到達したら、フローの増加量を返す
            return fNow

        # 前回の続きから、探索を再開する
        iSt = iNext[vNow]
        for i, (v2, cap, iRev) in enumerate(adjL[vNow][iSt:], iSt):
            if dist[vNow] < dist[v2] and cap > 0:
                # 始点からの最短距離が増加する頂点への辺の容量に空きがある場合、探索する
                df = DFS(v2, vEn, min(fNow, cap))
                if df > 0:
                    # 始点から終点までの経路を遡って、辺のフローを変更する
                    adjL[vNow][i][1] -= df
                    adjL[v2][iRev][1] += df
                    return df

            iNext[vNow] += 1

        # 現在の頂点からの探索先がない場合、ゼロを返す
        return 0


    numV = len(adjL)
    MaximumFlow = 0
    while True:
        # 始点からの最短距離を、BFSで求める
        dist = [-1] * numV
        BFS(vSt)
        if dist[vEn] == -1:
            # 終点までの経路が見つからない場合、最大フローの値を返す
            return MaximumFlow

        iNext = [0] * numV
        while True:
            # 残余グラフの始点から終点までの経路（増加パス）を、DFSで探索する
            df = DFS(vSt, vEn, float('inf'))

            if df == 0:
                # 経路が見つからない場合、ループを抜ける
                break

            # フローを加算する
            MaximumFlow += df


N = int(input())
As = list(map(int, input().split()))

adjList = [[] for v in range(N + 2)]
for i, A in enumerate(As, 1):
    if A <= 0:
        addEdge(adjList, 0, i, -A)
    else:
        addEdge(adjList, i, N + 1, A)

for i in range(1, N + 1):
    for j in range(2 * i, N + 1, i):
        addEdge(adjList, i, j, float('inf'))

# Dinic法（最大フローを求める）
mf = Dinic(adjList, 0, N + 1)
print(sum([A for A in As if A > 0]) - mf)


Measured memory_bytes: 3444
function main()
  
  (N, K) = map(x -> parse(Int,x), split(readline()))
  P = map(x -> parse(Int,x), split(readline()))
  
  ex = []
  
  for n in P
    push!(ex, (n+1)/2)
  end
  
  ans = sum(ex[1:K])
  check = ans
  
  for i in 1:N-K
    check -= ex[i]
    check += ex[i+K]
    ans = max(ans, check)
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 172264
n, k = map(int, input().split())
D = set(map(int, input().split()))

num = set(i for i in range(10))

D = num - D

for i in range(n, 100000):
    for _ in str(i):
        if int(_) not in D:
            break
    else:
        print(i)
        break


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


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

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

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

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

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i,N) cin >> a[i];
    int sum[9];
    rep(i,9) sum[i]=0;
    for(int i=0; i<N; i++){
        int tmp=400;
        if(3200<=a[i]){
            sum[8]++;
        }
        for(int j=0; j<8; j++){
            if(tmp-400<=a[i] && a[i]<tmp){
                sum[j]++;
                break;
            }
            tmp+=400;
        }
    }
    int amin=0, amax=0;
    for(int i=0; i<8; i++){
        if(sum[i]>0){
            amin++;
        }
    }
    amax = amin + sum[8];
    if(sum[7]==0 && sum[8]>0){
        amin++;
    }
    cout << amin << " " <<amax << endl;
    return 0;
}

Measured memory_bytes: 256