akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations_with_replacement as cmb

N, M, Q = map(int, input().split())
a = []
b = []
c = []
d = []
s = 0

for _ in range(Q):
    _a, _b, _c, _d = map(int, input().split())
    a.append(_a)
    b.append(_b)
    c.append(_c)
    d.append(_d)

for A in cmb(range(1,M+1),N):
    _s = 0
    for q in range(Q):
        if A[b[q]-1] - A[a[q]-1] == c[q]:
            _s += d[q]
    
    s = max(s,_s)

print(s)

Measured memory_bytes: 9144
#include<iostream>
#include<vector>
#include<algorithm>
#define f first
#define s second

using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef long long ll;
typedef pair<int,int> P;

mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++)
    for(int k=0;k<B.size();k++)
      for(int j=0;j<B[0].size();j++)
	C[i][j]+=A[i][k]*B[k][j];

  return C;
} 

mat pow(mat A,ll n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++)B[i][i]=1;
  while(n>0){
    if(n&1)B=mul(B,A);
    A=mul(A,A);
    n>>=1;
  }
  return B;
}

int main(void){

  int n,m,z,s,d;
  vector<P>G;

  while(cin >> n >> m >> z,n|m|z){
    G.clear();
    G.push_back(P(1,1));
    for(int i=0;i<m;i++){
      cin >> s >> d;
      G.push_back(P(s,d));
      G.push_back(P(d,s));
    }

    mat A(G.size(),vec(G.size()));
 
    for(int i=0;i<G.size();i++)
      for(int j=1;j<G.size();j++)
	if(i!=j && G[i].f!=G[j].s && G[i].s==G[j].f)A[i][j]=1;

    A=pow(A,z);

    bool fg=false;
    for(int i=0;i<A.size();i++)
      if(G[i].s==n && A[0][i])fg=true;

    cout << (fg?"yes":"no") << endl;
  }
  return 0;
}

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

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

    vector<long long> A(N);
    for (long long &a : A)
    {
        cin >> a;
    }

    vector<long long> dp(205, 0);
    dp.back() = 1000;
    for (size_t i = 0; i < N; i++)
    {
        for (long long j = A[i]; j < dp.size(); j++)
        {
            dp[A[i]] = max(dp[A[i]], dp[j]);
        }
        for (long long j = 100; j < A[i]; j++)
        {
            dp[A[i]] = max(dp[A[i]], dp[j] + (A[i] - j) * (dp[j] / j));
        }
    }
    long long ans = 0;
    for (long long a : dp)
    {
        ans = max(ans, a);
    }
    cout << ans << endl;
}


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

int n;

int main()
{
	scanf("%d",&n);
	if(n<=2) return puts("No"),0;
	for(int i=0;i<20;++i) if(n==(1<<i)) return puts("No"),0;
	puts("Yes");
	printf("%d %d\n",2,1);
	printf("%d %d\n",1,3);
	printf("%d %d\n",3,n+2);
	printf("%d %d\n",n+2,n+1);
	printf("%d %d\n",n+1,n+3);
	for(int i=4;i<n;i+=2)
	{
		printf("%d %d\n",1,i+1);
		printf("%d %d\n",i,i+1);
		printf("%d %d\n",1,i+n);
		printf("%d %d\n",i+n,i+n+1);
	}
	if(!(n&1))
	{
		int cur=n^1;
		int up=1<<((int)log2(cur));
		printf("%d %d\n",n,up+n);
		printf("%d %d\n",n+n,cur^up&1?cur^up:(cur&up)+n);
	}
}


Measured memory_bytes: 2304
//02-03-20202

#include<bits/stdc++.h>
using namespace std;
#define MKM(i,a,b) for(int i=a;i<b;i++)
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n,a,c=0;
    cin>>n;

    MKM(i,0,n)
    {
        cin>>a;

        if(a%2==0)
        {
            if(a%3==0 || a%5==0)
                c=0;
            else
                {
                    c=1;
                    break;
                }
        }
    }

    if(c==1)
        cout<<"DENIED"<<"\n";
    else
        cout<<"APPROVED"<<"\n";

    return 0;   //:D

}


Measured memory_bytes: 256
while 1:
    h,w=map(int,input().split())
    if h+w==0:
        break
    else:
        for i in range(h):
            for n in range(w):
                if (i+n)%2==0:
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        print()


Measured memory_bytes: 7000
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
int N, M;
int A[303][303];
//---------------------------------------------------------------------------------------------------
int check(int x) {
    vector<queue<int>> vq(N);
    vector<int> used(M, 0);
    rep(y, 0, N) rep(x, 0, M) vq[y].push(A[y][x]);
 
    while(1) {
        map<int, int> m;
        rep(y, 0, N) m[vq[y].front()]++;
        vector<int> ng;
        fore(p, m) if (x < p.second) ng.push_back(p.first);
 
        if (ng.size() == 0) return 1;
 
        fore(j, ng) used[j] = 1;

        rep(y, 0, N) {
            while (!vq[y].empty() && used[vq[y].front()]) vq[y].pop();
            if (vq[y].empty()) return 0;
        }
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(y, 0, N) rep(x, 0, M) {
        cin >> A[y][x];
        A[y][x]--;
    }
    
    int ng = 0, ok = N;
    while (ng + 1 != ok) {
        int x = (ng + ok) / 2;
        if (check(x)) ok = x;
        else ng = x;
    }
    cout << ok << endl;
}

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

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

	if (a < b) swap(a, b);

	ll x = a * b;
	for (ll r = a % b; r != 0; r = a % b) {
		a = b;
		b = r;
	}

	cout << (x / b) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <stack>
#include <map>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;


int main() 
{
	int a[100]={};
	int x,y;
	while(cin>>x>>y)
	{
		if(x&&y)
		{
			a[x-1]++;
			a[y-1]++;
		}
		else
		{
			bool ans(true);
			for(int i=0;i<100;i++){
				if(i==0||i==1){if(a[i]%2!=1){ans=false;}}
				else{if(a[i]%2!=0)ans=false;}
				if(!ans)break;
			}
			if(ans)cout<<"OK"<<endl;
			else cout<<"NG"<<endl;
			REP(i,100)a[i]=0;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
n = gets.to_i
title = []
sec = []
for i in 0..n-1 do
  a,b = gets.split(" ")
  title.push(a)
  sec.push(b.to_i)
end
x = gets.chomp
flag = false
cnt = 0
for i in 0..n-1 do
  if flag then
    cnt += sec[i]
  elsif x==title[i] then
    flag = true
  end
end
puts(cnt)

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

int main() {
    long long n, ans, rcnt = 0, gcnt = 0, bcnt = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; ++i) {
        if(s[i] == 'R') ++rcnt;
        if(s[i] == 'G') ++gcnt;
        if(s[i] == 'B') ++bcnt;
    }
    ans = rcnt * gcnt * bcnt;

    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            int k = j + j - i;
            if(k < n) {
                if(s[i] == s[j]) continue;
                if(s[i] == s[k]) continue;
                if(s[j] == s[k]) continue;
                --ans;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int h = 0;
  int m = 0;
  int n = 0;
  int o = 0;
  int p = 0;
  // ここにプログラムを追記
  for (int i = 0; i < N ; i ++){
    string X;
    cin >> X;
    if (X == "P" && m == 0){
        h ++;
        m ++;
    }
    else if(X == "W" && n == 0){
        h ++;
        n ++;
    }
    else if (X == "G" && o == 0){
        h ++;
        o ++;
    }
    else if (X == "Y" && p == 0){
        h ++;
        p ++;
    }
    
  }
  if (h == 3){
        cout << "Three";
    }else if(h == 4){
        cout << "Four";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long 
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define N ((ll)(2e6+100))
#define MAX ((ll)(1e16+100))
#define ARRS ((ll)(3e5+100))
#define MOD ((ll)(1e9+7))
#define M1 ((ll)(1001783))
#define M2 ((ll)(1001941))
#define M3 ((ll)(1002073))
#define pb push_back


ll n,m;
ll a[ARRS];
ll b[ARRS];
string s;

bool get(ll i){

	string s;
	cout<<i<<endl;
	cin>>s;

	if(s[0]=='V')
		exit(0);
	else if(s[0]=='M')
		return 1;
	else return 0;

}

int main(){
	ll n;
	cin>>n;
	ll w=get(0);
	ll l=1,r=n-1;
	while(l<r){
		ll m=(l+r)/2;
		ll k=get(m);
		if(k==((m&1)^w))
			l=m+1;
		else r=m-1;
	}
	get(l);
}
 


Measured memory_bytes: 852
N = int(input())
A = sorted([int(_) for _ in input().split()])


def comb(n, r):
    res = 1
    for i in range(n - r + 1, n + 1):
        res *= i
    for i in range(1, r):
        res //= i
    return res


x = A.pop()
N -= 1
for i in range(N):
    if A[i] > x // 2:
        break
if abs(A[i] - x / 2) < abs(A[i - 1] - x / 2):
    print(x, A[i])
else:
    print(x, A[i - 1])


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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

#ifdef AZN_LIB
#pragma once
#endif

template <template <class> class Alloc = allocator> struct DisjointSet {
  vector<int, Alloc<int>> tree;

  DisjointSet(int n) : tree(n, -1) {}

  bool Unite(int a, int b) {
    a = Find(a);
    b = Find(b);
    if (a == b)
      return false;
    if (-tree[b] > -tree[a])
      swap(a, b);
    tree[a] += tree[b];
    tree[b] = a;
    return true;
  }

  int GetSize(int a) {
    return -tree[Find(a)];
  }

  bool IsSameSet(int a, int b) {
    return Find(a) == Find(b);
  }

  int Find(int node) {
    return tree[node] < 0 ? node : (tree[node] = Find(tree[node]));
  }
};

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n, m;
  if (not(cin >> n >> m))
    return;
  vector<ll> perm(n);
  RARA(p, perm) {
    cin >> p;
    --p;
  }
  DisjointSet<> dsu(n);
  VEVE(e, 0, m) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    dsu.Unite(a, b);
  }
  ll res = 0;
  VEVE(i, 0, n) {
    res += dsu.IsSameSet(i, perm[i]);
  }
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 11;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>

int main()
{
  unsigned long long int N, A, B;
  int X[100000];

  scanf("%lld %lld %lld", &N, &A, &B);
  int i;
  for (i = 0; i < N; i++)
    scanf("%d", &X[i]);
  unsigned long long int ans = 0;
  unsigned long long int tmp;
  for (i = 1; i < N; i++) {
    tmp = A * (X[i] - X[i-1]);
    if ( tmp > B)
      ans += B;
    else
      ans += tmp;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int MAX_N = 1001;
const ull B1 = 9973;
const ull B2 = 1e9 + 7;
int H, W, P, Q;
ull Hash[MAX_N][MAX_N], tmp[MAX_N][MAX_N];
char field[MAX_N][MAX_N], patterns[MAX_N][MAX_N];
void RollingHash(int n, int m, char ch[MAX_N][MAX_N])
{
    //行方向
    ull t1 = 1;
    for(int j = 0; j < Q; j++) t1 *= B1;
    for(int i = 0; i < n; i++)
    {
        ull e1 = 0;
        for(int j = 0; j < Q; j++) e1 = e1 * B1 + ch[i][j];
        for(int j = 0; j + Q <= m; j++)
        {
            tmp[i][j] = e1;
            if(j + Q < m) e1 = e1 * B1 - t1 * ch[i][j] + ch[i][j + Q];
        }
    }
    //双方向
    ull t2 = 1;
    for(int i = 0; i < P; i++) t2 *= B2;
    for(int j = 0; j + Q <= m; j++)
    {
        ull e2 = 0;
        for(int i = 0; i < P; i++) e2 = e2 * B2 + tmp[i][j];
        for(int i = 0; i + P <= n; i++)
        {
            Hash[i][j] = e2;
            if(i + P < n) e2 = e2 * B2 - t2 * tmp[i][j] + tmp[i + P][j];
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            cin >> field[i][j];
        }
    }
    cin >> P >> Q;
    for(int i = 0; i < P; i++)
    {
        for(int j = 0; j < Q; j++)
        {
            cin >> patterns[i][j];
        }
    }
    RollingHash(P, Q, patterns);
    ull f = Hash[0][0];
    RollingHash(H, W, field);
    for(int i = 0; i + P <= H; i++)
    {
        for(int j = 0; j + Q <= W; j++)
        {
            //cout << Hash[i][j] << " " << f << endl;
            if(Hash[i][j] == f) cout << i << " " << j << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 19776
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, k = LI()
    a = LI()
    a.sort(key=abs, reverse=True)
    ans = 1
    if n - a.count(0) < k:
        print(0)
        return
    t = 0
    L = None
    R= inf
    for ai in a[:k]:
        if ai < 0:
            t ^= 1
            L = ai
        if ai > 0:
            R = ai
        ans *= ai
        ans %= mod
    if k == n:
        print(ans)
        return
    if t:
        if max(a) <= 0:
            ans = 1
            for i in range(k):
                ans *= a[-i - 1]
                ans %= mod
            print(ans)
        else:
            A = min(a[k:])
            B = max(a[k:])
            if A >= 0:
                ans *= pow(L, mod - 2, mod)
                ans *= B
            else:
                if A * L > B * R:
                    ans *= pow(R, mod - 2, mod)
                    ans *= A
                else:
                    ans *= pow(L, mod - 2, mod)
                    ans *= B
            print(ans % mod)
    else:
        print(ans)
    return


#main
if __name__ == '__main__':
    solve()


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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        for (int j = i; j < S.length(); j++) {
            bool is_ok = true;
            for (int k = i; k <= j; k++) {
                if (S[k] != 'A' && S[k] != 'C' && S[k] != 'G' && S[k] != 'T') {
                    is_ok = false;
                }
            }
            if (is_ok) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
is_yes = True
for i in range(N-1, 0, -1):
    if H[i-1] <= H[i]:
        continue
    H[i-1] -= 1
    if H[i-1] <= H[i]:
        continue
    is_yes = False
    break

if is_yes:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63856
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
using namespace std;

static const int MAX=100000;
static const int INFTY=(1<<29);

vector<int> G[MAX];
list <int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
	queue<int> q;
	q.push(s);
	V[s]=true;
	while(q.size()){
		int u=q.front();
		q.pop();
		out.push_back(u);
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			indeg[v]--;
			if(indeg[v]==0 && !V[v]){
				V[v]=true;
				q.push(v);
			}
		}
	}
}

void tsort(){
	memset(indeg,0,sizeof(indeg));
	for(int u=0;u<N;u++){
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			indeg[v]++;
		}
	}
	for(int u=0;u<N;u++){
		if(indeg[u]==0 && !V[u])bfs(u);
	}
	for(list<int>::iterator it=out.begin();it!=out.end();it++){
		cout << *it << endl;
	}
}

int main(void){
	int s,t,M;
	scanf("%d %d",&N,&M);
	memset(V,false,sizeof(V));
	for(int i=0;i<M;i++){
		scanf("%d %d",&s,&t);
		G[s].push_back(t);
	}
	tsort();
	return 0;
	
}

Measured memory_bytes: 4772
n = int(input())
cards = [input() for i in range(n)]
perfect_cards = []

for i in range(1, 14):
    for j in ['S', 'H', 'C', 'D']:
        perfect_cards.append(j + ' ' + str(i))

r_cards = list(set(perfect_cards) - set(cards))
S_cards = sorted([i for i in r_cards if 'S' in i], key=lambda x: int(x[2:]))
H_cards = sorted([i for i in r_cards if 'H' in i], key=lambda x: int(x[2:]))
C_cards = sorted([i for i in r_cards if 'C' in i], key=lambda x: int(x[2:]))
D_cards = sorted([i for i in r_cards if 'D' in i], key=lambda x: int(x[2:]))
r_cards = S_cards + H_cards + C_cards + D_cards

for i in r_cards:
    print(i)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  
  if (s[0]==s[1] && s[2]==s[3] && s[0]==s[2]){
    cout << "No" << endl;
  }
  else if (s[0]==s[1] && s[2]==s[3]){
    cout << "Yes" << endl;
  }
 else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#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;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n;
	cin>>n;
	ll arr[3][n];
	REP(i,0,n){
		cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
	}
	ll dp[3][n];
	dp[0][0] = arr[0][0]; dp[1][0] = arr[1][0]; dp[2][0] = arr[2][0];

	REP(i,1,n){
		dp[0][i] = max(dp[1][i-1] + arr[0][i],dp[2][i-1] + arr[0][i]);
		dp[1][i] = max(dp[0][i-1] + arr[1][i],dp[2][i-1] + arr[1][i]);
		dp[2][i] = max(dp[0][i-1] + arr[2][i],dp[1][i-1] + arr[2][i]);
	}
	cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
	return 0;
}



Measured memory_bytes: 4992
#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;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int now = h[n-1];
  for (int i = n-2; i >= 0; --i) {
    if (h[i] - 1 > now) {
      cout << "No" << endl;
      return 0;
    }
    if (h[i] < now) now = h[i]; 
  }
  cout << "Yes" << endl;
  return 0;
}

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

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

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

	int ans = 0;
	int flag = 1;

	while (flag) {
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 0) {
				A[i] /= 2;
			}
			else {
				flag = 0;
			}
		}
		if (flag) ans += 1;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
n,k,i=int(input()),1,2
v=n+1
p=print
if-n&n==n:p("No");exit()
p("Yes",v,3)
while i<n:p(1,i,i,i+1,1,v+i,v+i,n+i);i+=2;k*=1+(k*2<v)
if~n&1:p(n,v+k,n+n,n^k)

Measured memory_bytes: 9264
using System;
using System.Collections.Generic;
namespace _113C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str1 = Console.ReadLine().Split(' ');
            int N = int.Parse(str1[0]);//prefecture
            int M = int.Parse(str1[1]);//city
            int[][] str2 = new int[M][];
            for (int i = 0; i < M; i++)
            {
                str2[i] = new int[4];
                str2[i][0] = i;
                string[] str3 = Console.ReadLine().Split(' ');
                str2[i][1] = int.Parse(str3[0]);//prefecture
                str2[i][2] = int.Parse(str3[1]);

            }
            Array.Sort(str2, (x, y) => x[2] - y[2]);
            int[,] prefects = new int[M,2];
            int[] cities = new int[N];
            

            for (int j = 0; j < M; j++)
            {
                prefects[str2[j][0],0] = str2[j][1];
                prefects[str2[j][0],1] = cities[str2[j][1]-1]+1;
                cities[str2[j][1]-1]++;
            }

            for (int j = 0; j < M; j++)
            {
                
                //Console.Write(str2[j][0] + " ");
                string strb = "000000" + prefects[j,0].ToString();
                strb = strb.Substring(strb.Length - 6, 6);
                string stra = "000000" + prefects[j,1].ToString();
                stra = stra.Substring(stra.Length - 6, 6);
                Console.WriteLine(strb + stra);
            }

        }
    }
}


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

int	main() {
	int N;
	string S;
	cin >>N >>S;
	int x=0;
	int X=0;
	for (int i=0; i<S.size(); i++)
		if ('I'==S.at(i)) {
			x++;
			X=max(X, x);
		} else
			x--;
	cout <<X <<endl;
	return 0;
};


Measured memory_bytes: 256
#include<stdio.h>

int selectionSort(int A[], int N) {
    int count = 0, i, j, v;
    for(i = 0; i < N - 1; i++) {
        int minj = i;
        for(j = i; j < N; j++) {
            if(A[minj] > A[j]) minj = j;
        }
        v = A[i];
        A[i] = A[minj];
        A[minj] = v;
        if(i != minj) count++;
    }
    return count;
}

int main() {
    int A[100], N, i, count;
    scanf("%d", &N);
    for(i = 0; i < N; i++) scanf("%d", &A[i]);

    count = selectionSort(A, N);

    for(i = 0; i < N; i++) {
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", count);

    return 0; 
}


Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char map[101][101];
int dp[101][101];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", map[i]);
    if (map[0][0] == '#')
        dp[0][0] = 1;
    for (int i = 1; i < n; i++)
    {
        dp[i][0] = dp[i - 1][0];
        if (map[i][0] == '#' && map[i - 1][0] != '#')
            dp[i][0]++;
    }
    for (int i = 1; i < m; i++)
    {
        dp[0][i] = dp[0][i - 1];
        if (map[0][i] == '#' && map[0][i - 1] != '#')
            dp[0][i]++;
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j < m; j++)
        {
            dp[i][j] = dp[i][j - 1] + (map[i][j] == '#' && map[i][j - 1] != '#');
            dp[i][j] = min(dp[i - 1][j] + (map[i][j] == '#' && map[i - 1][j] != '#'), dp[i][j]);
        }
    }
    printf("%d\n", dp[n - 1][m - 1]);
    return 0;
}

Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
const int mx = 2000 * 100 + 5;
int ind[mx], dp[mx];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n, a;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a;
		a--;
		ind[a] = i;
	}
	dp[n - 1] = 1;
	int maxi = 1;
	for(int i = n - 2; i >= 0; i--){
		dp[i] = 1;
		if(ind[i] < ind[i + 1])
			dp[i] += dp[i + 1];
		maxi = max(maxi , dp[i]);
	}
	cout << n - maxi << endl;
	return 0;
}


Measured memory_bytes: 3328
import collections as col

def prime(n):
    ans = []
    num = n
    for i in range(2,n+1):
        if i%2==0 and i!=2: continue
        while num%i == 0: num //= i ; ans.append(i)
    return ans

n = int(input())
mod = 10**9 + 7

primes = []
for i in range(2,n+1): primes += prime(i)

cnt = col.Counter(primes)
ans = 1
for key,val in cnt.items(): ans *= (val + 1) ; ans %= mod
print(ans)


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

typedef long long ll;
const ll MOD = 1000000007;

//Fast Exponentiation
ll fexp(ll base, ll exp, ll mod) {
    if (base >= mod) base %= mod;
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) result = (result * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

const int N = 100003;
int dp[N]; // dp[i] = number of coprime sequences of length n, values between 1 and i only

// int ans[N]; // ans[i] = number of sequences of length n, val bw 1 and k, gcd = i

int main() {
    int k; scanf("%d", &k);
  
    int n = 3;

    // base case
    dp[1] = 1;

    // iterate
    for (int i = 2; i <= k; i++) {
        int up = 1;
        while (up * up < i) ++up;

        ll sub = 0;

        for (int j = 2; j < up; j++) {
            sub += dp[i / j];
            if (sub >= MOD) sub -= MOD;
        }

        int val = i / up;
        for (int j = 1; j <= val; j++) {
            int lo = i / (j + 1) + 1, hi = i / j;
            int amt = hi - lo + 1;

            ll prod = 1ll * amt * dp[j];
            if (prod >= MOD) prod %= MOD;

            sub += prod;
            if (sub >= MOD) sub -= MOD;
        }

        dp[i] = (fexp(i, n, MOD) + (MOD - sub)) % MOD;
    }

    // print the answer
    int ans = 0;

    for (int j = 1; j <= k; j++) {
        ll add = 1ll * j * dp[k / j];
        if (add >= MOD) add %= MOD;

        ans += add;
        if (ans >= MOD) ans -= MOD;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
#include <stack>

using namespace std;

#define INF 2e9 + 9
#define ALL(v) v.begin(), v.end()
#define Int int64_t
#define pll pair<Int, Int>
template <class T>
using pql = priority_queue<T, vector<T>>;
template <class T>
using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) \
    Int n;    \
    cin >> n;
#define LL(...)       \
    Int __VA_ARGS___; \
    cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for (Int i = s; i < n; i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) \
    if (maxer < updater)        \
        maxer = updater;

vector<vector<Int>> to;
vector<Int> d;
vector<Int> f;
/*
Int dfs(Int from, Int time){
    if (d[from] != 0) return 0;
    Int maxer = time;
    d[from] = time;
    Int cnt = 0;
    for (auto next : to.at(from)){
        maxer= max(dfs(next,maxer+1),maxer);
    }
    if (maxer == 0) return f[from] = d[from];
    return f[from] = maxer+1;
}*/


/*
    stackの挿入ルール
    未探索だと思って追加する時はpairの2つめの値を0とする
    既探索だけど、完了時刻を確認するためにstackに追加する時は-1とする
    -1ならnowtimeを追加、nowtime++して次へ飛ばす
    違ったら、自分が本当に未探索かどうかを判断した上で、未探索であれば
    自分の発見時刻をメモ、次に探索する所を追加して、ターン終了
*/
Int dfs(Int x, Int t){
    Int nowtime = t;
    stack<pll> st;
    st.push({x,0});
    while(!st.empty()){
        //stackから取り出してきて
        auto z = st.top();
        Int from = z.first;
        Int op = z.second;
        st.pop();

        if (op == -1) { // 完了時刻の記入
            f[from] = nowtime;
            nowtime++;
        }

        if (d[from] != 0) continue;

        //ここから未探索確定
        st.push({from,-1});
        d[from] = nowtime;
        nowtime++;
        for (int i = to[from].size() - 1; i >= 0; i--){//次探索する箇所は、未探索だと思って挿入
            st.push({to[from][i],0});
        }
    }
    return nowtime;
}



int main() {
    Int n;
    cin >> n;
    to.resize(n);
    d.resize(n);
    f.resize(n);

    REP(n,i){
        Int u, k;
        cin >> u >> k;
        REP(k,kk) {
            Int x;
            cin >> x;
            x--;
            to.at(i).push_back(x);
        }
    }
    
    Int time = 1;
    
    REP(n,i){
        if (d[i] == 0){
            //time = dfs(i,time) + 1;
            time = dfs(i,time);
        }
    }  

    for (Int i = 0 ; i < n; i++){
        cout << i + 1 << " " << d[i] << " " << f[i] << endl; 
    }

}


Measured memory_bytes: 3148
#include<stdio.h>
#include<iostream>
using namespace std;
long long int n;
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	cin>>n;
	if(n==1||n==2||n==3||n==4||n==5||n==6)
	cout<<1;
	else if(n==7||n==8||n==9||n==10)
	cout<<2;
	else 
	if(n%11==0)
	cout<<(n/11)*2;
	else if(n%11<=6)
	cout<<(n/11)*2+1;
	else cout<<(n/11)*2+2;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

ll h, w;
string a[10];
int main() {
    cin>>h>>w;
    REP(i, 0, h) cin>>a[i];

    ll cnt=0;
    REP(i, 0, h){
        REP(j, 0, w){
            if(a[i][j]=='#') cnt++;
        }
    }
    if(cnt==h+w-1) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

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

int main () {
    int N;
    string S, T, c1;
    char c;
    cin >> N >> S;

    for (int i = 0; i < S.size(); i++) {
        if ((S[i] + N) > 'Z') {
            c = 'A' + (S[i] + N - 'Z' - 1);
            c1 = c;
            T = T + c1;
        } else {
            c = S[i] + N;
            c1 = c;
            T = T + c1;
        }
    }

    cout << T << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  cout << N-K+1 << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]

    b_list = [-1 for i in range(512345)]
    left = 212345
    right = left+1
    for i in range(n):
        if (i+1)%2 == n%2:
            b_list[left] = a_list[i]
            left -= 1
        else:
            b_list[right] = a_list[i]
            right += 1

    print(' '.join([str(i) for i in b_list[left+1:right]]))

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 33856
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}

void solve()
  {
  	int n; cin>>n;
  	vi v(n);
  	f(i, 0, n-1) cin>>v[i];
  	vi dp(n, 0);
  	dp[1]=abs(v[1]-v[0]);
  	dp[2]=abs(v[2]-v[0]);
  	for( int i=3; i<n; i++)
  	 dp[i]=min( dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
  	cout<<dp[n-1]<<endl;

  }

int32_t main ()
{
//fio
int t=1; 
//cin>>t; 
while(t--){
	solve();
}
 
}








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

int main()
{
    string s1,s2;
    int i,cnt=0;
    cin>>s1>>s2;
    for(i=0; i<s1.size(); i++)
    {
        if(s1[i]==s2[i])
            cnt++;
    }
    cout<<cnt<<endl;
}

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

using namespace std;

const int maxn = 100010;

set<int> s[maxn];
queue<pair<int, int> > q;

int f[maxn];
int find(int x) {
	return f[x] == x ? x : f[x] = find(f[x]);
}

int main() {
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++i) f[i] = i;
	for(int i = 0; i < (n - 1) << 1; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		if(s[u].count(v)) {
			q.push({u, v});
		} else {
			s[u].insert(v);
			s[v].insert(u);
		}
	}
	while(!q.empty()) {
		int u, v;
		tie(u, v) = q.front(); q.pop();
		u = find(u), v = find(v);
		if(s[u].size() < s[v].size()) swap(u, v);
		s[u].erase(v);
		s[v].erase(u);
		for(auto x: s[v]) {
			s[x].erase(v);
			if(s[x].count(u)) {
				q.push({u, x});
			} else {
				s[x].insert(u);
				s[u].insert(x);
			}
		}
		s[v].clear();
		f[v] = u;
	}
	int root = find(1);
	bool flag = true;
	for(int i = 2; i <= n; ++i)
		if(find(i) != root) flag = false;
	puts(flag ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 24064
#include <stdio.h>

void c_copy(int c_tmp[], int data[], int p, int c, int n) {
  int i = 0;
  for (i = 0; i < c; i++) {
    c_tmp[i] = data[n-p+i-c+1];
    //    printf("i =%d n=%d n-p+i-c = %d\n",i,n,n-p+i-c+1);
  }
}

void move(int data[], int p, int c, int n) {
  int i;
  for (i = n-p+1; i < n; i++) {
    data[i-c] = data[i];
  }
}

void tmp_in(int c_tmp[], int data[], int p, int c, int n) {
  int i;  
  for (i = n-c; i < n; i++) {
    data[i] = c_tmp[i-n+c];
  }
}

void print(int data[], int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ",data[i]);
  }
  puts("");
}

int main(void) {
  int data[200];
  int n[1000];
  int r[1000];
  int p[1000][200];
  int c[1000][200];
  int c_tmp[1000][200];
  int i = 0, j = 0;
  int N;

  while (1) {
    scanf("%d", &n[i]);
    scanf("%d", &r[i]);
    if (n[i] == r[i] && n[i] == 0) {
      break;
    }
    for (j = 0; j < r[i]; j++) {
      scanf("%d", &p[i][j]);
      scanf("%d", &c[i][j]);
    }
    i++;
  }
  N = i;

  
  for (i = 0; i < N; i++) {
    for (j = 0; j < 200; j++) {
      data[j] = j+1;
    }
    for (j = 0; j < r[i]; j++) {
      // print(data, n[i]);//
      
      c_copy(c_tmp[i], data, p[i][j], c[i][j], n[i]);//
      // printf("c_copy = ");
      // print(c_tmp[i], n[i]);//
      
      move(data, p[i][j], c[i][j], n[i]);
      // printf("move\n");
      // print(data, n[i]);
      
      tmp_in(c_tmp[i], data, p[i][j], c[i][j], n[i]);
      //    print(data, n[i]);
      // puts("");
    }
    printf("%d\n",data[n[i]-1]);
  }
  
  return 0;
}

Measured memory_bytes: 2060
#include <cstdio>
#include <queue>

using namespace std;

char s[512][512];
bool vis[512][512];

int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
  
  for (int i = 0; i < H; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < W; j++) {
      if ((i + j) % 2) s[i][j] ^= ('.' ^ '#');
    }
  }
  
  long long ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vis[i][j]) continue;
      int tmp[2] = {0, 0};
      tmp[(i + j) % 2]++;
      queue<pair<int, int>> q;
      q.push(make_pair(i, j)); vis[i][j] = true;
      while (q.size()) {
        pair<int, int> p = q.front(); q.pop();
        for (int d = 0; d < 4; d++) {
          pair<int, int> np = p;
          np.first += dy[d]; np.second += dx[d];
          if (!(0 <= np.first && np.first < H && 0 <= np.second && np.second < W)) {
            continue;
          }
          if (vis[np.first][np.second] || s[np.first][np.second] != s[i][j]) continue;
          vis[np.first][np.second] = true;
          tmp[(np.first + np.second) % 2]++;
          q.push(np);
        }
      }
      ans += (long long)tmp[0] * tmp[1];
    }
  }
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;
	cin>>n;
	vi a(n);
	rep(i,n)cin>>a[i];
	vi l(n+1),r(n+1),m(n);

	l[0]=0;
	r[n]=0;
	rep(i,n){
		l[i+1]=gcd(l[i],a[i]);
	}
	for(int i=n-1;i>=0;i--){
		r[i]=gcd(r[i+1],a[i]);
	}

	// rep(i,n+1) cout<<' '<<r[i];
	// cout<<endl;
	int ans=0;
	rep(i,n){
		// cout<<l[i]<<' '<<r[i+1]<<endl;
		chmax(ans,gcd(l[i],r[i+1]));
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 6348
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

const long long MAXN = 1e6 + 1;
const long long ZB = 1e18;
const long long MOD = 1e9 + 7;
using namespace std;

typedef pair<int, int> pii;


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

void fail() {
    cout << -1;
    exit(0);
}



#define ll long long

ll a[MAXN];
ll  b[MAXN];


int N(int i, int k) {
    if (i == k) return 1;
    return i + 1;
}
int P(int i, int k) {
    if (i == 1) return k;
    return i - 1;
}
main(){
    int n = readInt();
    for (int i = 1; i <= n; i++) {
        a[i] = readInt();
    }
    queue<int> que;
    for (int i = 1; i <= n; i++) {
        b[i] = readInt();
        if (b[i] < a[i]) fail();
        que.push(i);
    }

    ll ans = 0;

    while (que.size()) {
        int i = que.front(); que.pop();
        ll near = b[N(i, n)] + b[P(i, n)];
        ll u = (b[i] - a[i]) / near;
        if (u <= 0) continue;
        ans += u;
        b[i] -= near * u;
        que.push(P(i, n));
        que.push(N(i, n));
    }

    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i]) fail();
    }

    cout << ans << endl;

    return 0;
}



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

int main(){
    int N,K,ans=0;
    cin >> N >> K;
    vector<int> h(N);
    for(int i=0;i<N;++i) cin >> h[i];
    for(int i=0;i<N;++i){
        if(h[i]>=K) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x7ffffff;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	bool elf = false;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 2 != 0) elf = true;
	}
	if (elf) cout << "first" << endl;
	else cout << "second" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  vector<int> a;
  a.push_back(0);
  REP(i,n){
    int x; cin >> x;
    a.push_back(x);
  }
  a.push_back(0);// n+2までの配列

  int sum = 0;
  REP2(i,1,n+2){
    sum += abs(a[i] - a[i-1]);
  }

  REP(i,n){
    int pos = i + 1;
    ll ans = sum;
    ans -= abs(a[pos]-a[pos-1])+abs(a[pos]-a[pos+1]);
    ans += abs(a[pos+1]-a[pos-1]);
    cout << ans << endl;
  }
  //cout << sum << endl;


  return 0;
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev, col;
	Edge(ll _to, ll _cap, ll _rev, ll _col) {
	to = _to; cap = _cap; rev = _rev; col=_col;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap, ll col) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size(), col));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1, col));
}

void solve(){
    ll n;
    cin>>n;
    ll n2=1<<n;
    Array s(n2);
    REP(i,n2) cin>>s[i];

    sort(all(s));
    vec<int> now;
    now.push_back(s.back());
    s.back()==-1;

    REP(i,n){
        vec<int> pre=now;
        sort(all(pre));
        int si=n2-1;
        while(pre.size()>0&&si>=0){
            if(s[si]==-1){
                --si;
                continue;
            }
            if(s[si]<pre.back()){
                now.push_back(s[si]);
                pre.pop_back();
                s[si]=-1;
            }
            --si;
        }
        if(pre.size()>0){
            cout<<"No"<<en;
            return;
        }
    }
    cout<<"Yes"<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3956
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int rs[MAX_N], cs[MAX_N];
int dp[MAX_N][MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> rs[i] >> cs[i];

  for (int i = 0; i < n; i++) dp[i][i] = 0;

  int sum = 0;

  for (int l = 1; l < n; l++)
    for (int i0 = 0, i1 = l; i1 < n; i0++, i1++) {
      dp[i0][i1] = INF;
      for (int j = i0; j < i1; j++) {
	int d = rs[i0] * cs[j] * cs[i1] + dp[i0][j] + dp[j + 1][i1];
	if (dp[i0][i1] > d) dp[i0][i1] = d;
      }
    }

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

Measured memory_bytes: 1184